From c6e5a836ea7a143f471f9d4ecbd53786970435d6 Mon Sep 17 00:00:00 2001 From: Djeeberjr Date: Mon, 19 Dec 2022 17:35:14 +0100 Subject: [PATCH] Net improvments --- src/kernel/net/Net.hx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/kernel/net/Net.hx b/src/kernel/net/Net.hx index 5e7b710..7168689 100644 --- a/src/kernel/net/Net.hx +++ b/src/kernel/net/Net.hx @@ -1,5 +1,6 @@ package kernel.net; +import haxe.ds.ReadOnlyArray; using tink.CoreApi; import kernel.net.Package.NetworkID; @@ -37,6 +38,14 @@ class Net { for (interf in interfaces){ setupInterf(interf); } + + setupPingHandle(); + } + + private function setupPingHandle() { + this.registerProto('ping', pack -> { + this.respondTo(pack, pack.data); + }); } private function setupInterf(interf: INetworkInterface) { @@ -204,7 +213,7 @@ class Net { **/ public function ping(toID: NetworkID): Promise { return new Promise((resolve,reject)->{ - this.sendAndAwait(toID,"ping",null).map(pack -> { + this.sendAndAwait(toID,"ping",null).handle(pack -> { switch pack { case Success(_): resolve(true); @@ -215,4 +224,14 @@ class Net { return null; }); } + + public function getActiveProtocols(): ReadOnlyArray { + var arr = new Array(); + + for (proto in protoHandlers.keys()) { + arr.push(proto); + } + + return arr; + } }