diff --git a/src/kernel/Init.hx b/src/kernel/Init.hx index ac4c397..d2b96e2 100644 --- a/src/kernel/Init.hx +++ b/src/kernel/Init.hx @@ -12,10 +12,6 @@ class Init { public static function initKernel() { // Init singeltons here because haxe is confused about the order to create them. KernelEvents.instance = new KernelEvents(); - MainLoop.add(() -> { - KernelEvents.instance.startEventLoop(); - },1); - Peripheral.instance = new Peripheral(); WindowManager.instance = new WindowManager(); @@ -25,8 +21,6 @@ class Init { Routing.instance = new Routing(); Net.instance = new Net(); - Routing.instance.init(); - // Register default terminate handler KernelEvents.instance.onTerminate.handle(_->{ OS.reboot(); @@ -34,7 +28,13 @@ class Init { Debug.printBuildInfo(); - Log.moveToOutput("main"); + + Routing.instance.init(); + + MainLoop.add(()->{ + KernelEvents.instance.startEventLoop(); + }); + } } diff --git a/src/kernel/net/Routing.hx b/src/kernel/net/Routing.hx index 2ac4193..fca7f65 100644 --- a/src/kernel/net/Routing.hx +++ b/src/kernel/net/Routing.hx @@ -74,7 +74,11 @@ class Routing { data: null } - interf.send(pack.fromID,Net.instance.networkID,response); + // HACK: Because Lua is singelthreaded the computer we respond to can get overwhelmed with + // the responses and can swollow events. + new Timer(Net.instance.networkID / 3,()->{ + interf.send(response.toID,Net.instance.networkID,response); + }); } private function genRouteList(): Array<{id:NetworkID,cost:Int}> { @@ -109,18 +113,16 @@ class Routing { return; } - Log.debug("a"); - var fullCost = cost+interf.getBaseRoutingCost(); if (this.routingTable.exists(toID)){ if (this.routingTable[toID].cost > fullCost){ - Log.debug("Better route: " + toID + " -> " + interf.name() + ":$"+fullCost); + Log.info("Better route: " + toID + " -> " + interf.name() + ":$"+fullCost); this.routingTable[toID] = {interf:interf,cost:cost + interf.getBaseRoutingCost()}; } }else{ this.routingTable[toID] = {interf:interf,cost:cost + interf.getBaseRoutingCost()}; - Log.debug("New route: " + toID + " -> " + interf.name() + ":$"+fullCost); + Log.info("New route: " + toID + " -> " + interf.name() + ":$"+fullCost); this.onNewNeigborTrigger.trigger(toID); } } diff --git a/src/kernel/peripherals/Modem.hx b/src/kernel/peripherals/Modem.hx index 3875f74..c367c2a 100644 --- a/src/kernel/peripherals/Modem.hx +++ b/src/kernel/peripherals/Modem.hx @@ -21,8 +21,8 @@ class Modem implements INetworkInterface implements IPeripheral { KernelEvents.instance.onModemMessage.handle(params ->{ if (params.addr == this.addr){ var pack:Package = { - fromID: params.replyChannel, - toID: params.channel, + fromID: params.message.fromID, + toID: params.message.toID, msgID: params.message.msgID, type: params.message.type, data: params.message.data,