routing fix

This commit is contained in:
Djeeberjr 2022-03-01 12:59:23 +01:00
parent 4903014ebd
commit ecf4f9c719
3 changed files with 16 additions and 14 deletions

View File

@ -12,10 +12,6 @@ class Init {
public static function initKernel() { public static function initKernel() {
// Init singeltons here because haxe is confused about the order to create them. // Init singeltons here because haxe is confused about the order to create them.
KernelEvents.instance = new KernelEvents(); KernelEvents.instance = new KernelEvents();
MainLoop.add(() -> {
KernelEvents.instance.startEventLoop();
},1);
Peripheral.instance = new Peripheral(); Peripheral.instance = new Peripheral();
WindowManager.instance = new WindowManager(); WindowManager.instance = new WindowManager();
@ -25,8 +21,6 @@ class Init {
Routing.instance = new Routing(); Routing.instance = new Routing();
Net.instance = new Net(); Net.instance = new Net();
Routing.instance.init();
// Register default terminate handler // Register default terminate handler
KernelEvents.instance.onTerminate.handle(_->{ KernelEvents.instance.onTerminate.handle(_->{
OS.reboot(); OS.reboot();
@ -34,7 +28,13 @@ class Init {
Debug.printBuildInfo(); Debug.printBuildInfo();
Log.moveToOutput("main"); Log.moveToOutput("main");
Routing.instance.init();
MainLoop.add(()->{
KernelEvents.instance.startEventLoop();
});
} }
} }

View File

@ -74,7 +74,11 @@ class Routing {
data: null 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}> { private function genRouteList(): Array<{id:NetworkID,cost:Int}> {
@ -109,18 +113,16 @@ class Routing {
return; return;
} }
Log.debug("a");
var fullCost = cost+interf.getBaseRoutingCost(); var fullCost = cost+interf.getBaseRoutingCost();
if (this.routingTable.exists(toID)){ if (this.routingTable.exists(toID)){
if (this.routingTable[toID].cost > fullCost){ 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()}; this.routingTable[toID] = {interf:interf,cost:cost + interf.getBaseRoutingCost()};
} }
}else{ }else{
this.routingTable[toID] = {interf:interf,cost:cost + interf.getBaseRoutingCost()}; 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); this.onNewNeigborTrigger.trigger(toID);
} }
} }

View File

@ -21,8 +21,8 @@ class Modem implements INetworkInterface implements IPeripheral {
KernelEvents.instance.onModemMessage.handle(params ->{ KernelEvents.instance.onModemMessage.handle(params ->{
if (params.addr == this.addr){ if (params.addr == this.addr){
var pack:Package = { var pack:Package = {
fromID: params.replyChannel, fromID: params.message.fromID,
toID: params.channel, toID: params.message.toID,
msgID: params.message.msgID, msgID: params.message.msgID,
type: params.message.type, type: params.message.type,
data: params.message.data, data: params.message.data,