wip: switch

This commit is contained in:
Dmitriy Ryajov 2019-08-29 23:17:07 -06:00
parent 5eced0abee
commit e5be1fcaee
1 changed files with 10 additions and 10 deletions

View File

@ -10,33 +10,33 @@
import tables
import chronos
import connection, transport, stream,
peerinfo, multiaddress, multistreamselect,
protocol
multistreamselect, protocol,
peerinfo, multiaddress
type
Switch* = ref object of RootObj
peerInfo*: PeerInfo
connections*: TableRef[string, Connection]
transports*: seq[Transport]
protocols*: seq[Protocol]
ms*: MultisteamSelect
peerInfo*: PeerInfo
connections*: TableRef[string, Connection]
transports*: seq[Transport]
protocols*: seq[LPProtocol]
ms*: MultisteamSelect
proc newSwitch*(peerInfo: PeerInfo, transports: seq[Transport]): Switch =
new result
result.peerInfo = peerInfo
result.ms = newMultistream()
result.transports = transports
result.protocols = newSeq[switchtypes.Protocol]()
result.protocols = newSeq[LPProtocol]()
result.connections = newTable[string, Connection]()
proc dial*(s: Switch, peer: PeerInfo, proto: string = ""): Future[Connection] {.async.} = discard
proc mount*(s: Switch, protocol: protocol.Protocol) = discard
proc mount*(s: Switch, protocol: LPProtocol) = discard
proc start*(s: Switch) {.async.} =
# TODO: how bad is it that this is a closure?
proc handle(conn: Connection): Future[void] {.closure, gcsafe.} =
discard
s.ms.handle(conn)
for t in s.transports: # for each transport
for a in s.peerInfo.addrs: