adapt rendezvous server protocol to multi-server probing

This commit is contained in:
Christian Ulrich 2020-11-14 14:33:28 +01:00
parent 278f066797
commit b7236bfe45
No known key found for this signature in database
GPG Key ID: 8241BE099775A097
1 changed files with 8 additions and 5 deletions

View File

@ -9,13 +9,15 @@ type
Client = object Client = object
sock: AsyncSocket sock: AsyncSocket
ip: IpAddress ip: IpAddress
ports: seq[Port] port: Port
probedPorts: seq[Port]
# Requests # Requests
Register = object Register = object
peerId: string peerId: string
ip: IpAddress ip: IpAddress
ports: seq[Port] port: Port
probedPorts: seq[Port]
GetPeerinfo = object GetPeerinfo = object
peerId: string peerId: string
@ -88,7 +90,8 @@ proc processClient(client: AsyncSocket,
let req = parseMessage[Register](args[2]) let req = parseMessage[Register](args[2])
echo "register: ", req echo "register: ", req
peerId = req.peerId peerId = req.peerId
clients[peerId] = Client(sock: client, ip: req.ip, ports: req.ports) clients[peerId] = Client(sock: client, ip: req.ip, port: req.port,
probedPorts: req.probedPorts)
asyncCheck client.send(&"ok|{id}\n") asyncCheck client.send(&"ok|{id}\n")
of "get-endpoint": of "get-endpoint":
echo "get-endpoint" echo "get-endpoint"
@ -99,8 +102,8 @@ proc processClient(client: AsyncSocket,
let req = parseMessage[GetPeerinfo](args[2]) let req = parseMessage[GetPeerinfo](args[2])
echo "get-info: ", req echo "get-info: ", req
let peer = clients[req.peerId] let peer = clients[req.peerId]
let peerPorts = peer.ports.join(",") let probedPorts = peer.probedPorts.join(",")
asyncCheck client.send(&"ok|{id}|{peer.ip}|{peerPorts}\n") asyncCheck client.send(&"ok|{id}|{peer.ip}|{peer.port}|{probedPorts}\n")
of "notify-peer": of "notify-peer":
let req = parseMessage[NotifyPeer](args[2]) let req = parseMessage[NotifyPeer](args[2])
echo "notify-peer: ", req echo "notify-peer: ", req