@@ -36,7 +36,7 @@ Disk_ptr disk;
3636#include < isotime>
3737#include < net/inet4>
3838
39- void Service::start ( )
39+ static void start_acorn (net::Inet<net::IP4>& inet )
4040{
4141 /* * SETUP LOGGER */
4242 const int LOGBUFFER_LEN = 1024 *16 ;
@@ -45,7 +45,8 @@ void Service::start()
4545 logger_->flush ();
4646 logger_->log (" LUL\n " );
4747
48- OS::add_stdout ([] (const char * data, size_t len) {
48+ OS::add_stdout (
49+ [] (const char * data, size_t len) {
4950 // append timestamp
5051 auto entry = " [" + isotime::now () + " ]" + std::string{data, len};
5152 logger_->log (entry);
@@ -55,28 +56,10 @@ void Service::start()
5556
5657 // init the first legit partition/filesystem
5758 disk->init_fs (
58- [] (fs::error_t err, auto & fs)
59+ [&inet ] (fs::error_t err, auto & fs)
5960 {
6061 if (err) panic (" Could not mount filesystem...\n " );
6162
62- /* * IP STACK SETUP **/
63- // Bring up IPv4 stack on network interface 0
64- auto & stack = net::Inet4::ifconfig (5.0 ,
65- [] (bool timeout) {
66- printf (" DHCP resolution %s\n " , timeout ? " failed" : " succeeded" );
67- if (timeout)
68- {
69- /* *
70- * Default Manual config. Can only be done after timeout to work
71- * with DHCP offers going to unicast IP (e.g. in GCE)
72- **/
73- net::Inet4::stack ().network_config ({ 10 ,0 ,0 ,42 }, // IP
74- { 255 ,255 ,255 ,0 }, // Netmask
75- { 10 ,0 ,0 ,1 }, // Gateway
76- { 8 ,8 ,8 ,8 }); // DNS
77- }
78- });
79-
8063 // only works with synchronous disks (memdisk)
8164 list_static_content (disk);
8265
@@ -125,8 +108,8 @@ void Service::start()
125108 dashboard_->add (dashboard::Status::instance ());
126109 // Construct component
127110 dashboard_->construct <dashboard::Statman>(Statman::get ());
128- dashboard_->construct <dashboard::TCP>(stack .tcp ());
129- dashboard_->construct <dashboard::CPUsage>(500ms );
111+ dashboard_->construct <dashboard::TCP>(inet .tcp ());
112+ dashboard_->construct <dashboard::CPUsage>();
130113 dashboard_->construct <dashboard::Logger>(*logger_, static_cast <size_t >(50 ));
131114
132115 // Add Dashboard routes to "/api/dashboard"
@@ -154,7 +137,7 @@ void Service::start()
154137
155138
156139 /* * SERVER SETUP **/
157- server_ = std::make_unique<Server>(stack .tcp ());
140+ server_ = std::make_unique<Server>(inet .tcp ());
158141 // set routes and start listening
159142 server_->set_routes (router).listen (80 );
160143
@@ -178,3 +161,15 @@ void Service::start()
178161 }); // < disk
179162
180163}
164+
165+ void Service::start ()
166+ {
167+ auto & inet = net::Super_stack::get<net::IP4>(0 );
168+ if (not inet.is_configured ())
169+ {
170+ inet.on_config (start_acorn);
171+ }
172+ else {
173+ start_acorn (inet);
174+ }
175+ }
0 commit comments