add custom new proc

This commit is contained in:
Dmitriy Ryajov 2019-09-03 14:39:28 -06:00
parent 40e75a7635
commit cae4910427
1 changed files with 6 additions and 0 deletions

View File

@ -34,6 +34,7 @@ type
protos*: seq[string] protos*: seq[string]
Identify* = ref object of LPProtocol Identify* = ref object of LPProtocol
peerInfo*: PeerInfo
proc encodeMsg*(peerInfo: PeerInfo, observedAddrs: Multiaddress): ProtoBuffer = proc encodeMsg*(peerInfo: PeerInfo, observedAddrs: Multiaddress): ProtoBuffer =
result = initProtoBuffer() result = initProtoBuffer()
@ -79,6 +80,11 @@ proc decodeMsg*(buf: seq[byte]): IdentifyInfo =
discard pb.getString(5, result.protoVersion) discard pb.getString(5, result.protoVersion)
discard pb.getString(6, result.agentVersion) discard pb.getString(6, result.agentVersion)
proc newIdentify*(peerInfo: PeerInfo): Identify =
new result
result.peerInfo = peerInfo
result.init()
method init*(p: Identify) = method init*(p: Identify) =
proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} = proc handle(conn: Connection, proto: string) {.async, gcsafe, closure.} =
var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs()) var pb = encodeMsg(p.peerInfo, await conn.getObservedAddrs())