adapt rendezvous server protocol to multi-server probing

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