Net improvments

This commit is contained in:
Djeeberjr 2022-12-19 17:35:14 +01:00
parent a7dbdff535
commit c6e5a836ea

View File

@ -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<Bool> {
return new Promise<Bool>((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<String> {
var arr = new Array<String>();
for (proto in protoHandlers.keys()) {
arr.push(proto);
}
return arr;
}
}