mirror of https://github.com/vacp2p/nim-libp2p.git
wip: switch
This commit is contained in:
parent
5eced0abee
commit
e5be1fcaee
|
@ -10,33 +10,33 @@
|
||||||
import tables
|
import tables
|
||||||
import chronos
|
import chronos
|
||||||
import connection, transport, stream,
|
import connection, transport, stream,
|
||||||
peerinfo, multiaddress, multistreamselect,
|
multistreamselect, protocol,
|
||||||
protocol
|
peerinfo, multiaddress
|
||||||
|
|
||||||
type
|
type
|
||||||
Switch* = ref object of RootObj
|
Switch* = ref object of RootObj
|
||||||
peerInfo*: PeerInfo
|
peerInfo*: PeerInfo
|
||||||
connections*: TableRef[string, Connection]
|
connections*: TableRef[string, Connection]
|
||||||
transports*: seq[Transport]
|
transports*: seq[Transport]
|
||||||
protocols*: seq[Protocol]
|
protocols*: seq[LPProtocol]
|
||||||
ms*: MultisteamSelect
|
ms*: MultisteamSelect
|
||||||
|
|
||||||
proc newSwitch*(peerInfo: PeerInfo, transports: seq[Transport]): Switch =
|
proc newSwitch*(peerInfo: PeerInfo, transports: seq[Transport]): Switch =
|
||||||
new result
|
new result
|
||||||
result.peerInfo = peerInfo
|
result.peerInfo = peerInfo
|
||||||
result.ms = newMultistream()
|
result.ms = newMultistream()
|
||||||
result.transports = transports
|
result.transports = transports
|
||||||
result.protocols = newSeq[switchtypes.Protocol]()
|
result.protocols = newSeq[LPProtocol]()
|
||||||
result.connections = newTable[string, Connection]()
|
result.connections = newTable[string, Connection]()
|
||||||
|
|
||||||
proc dial*(s: Switch, peer: PeerInfo, proto: string = ""): Future[Connection] {.async.} = discard
|
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.} =
|
proc start*(s: Switch) {.async.} =
|
||||||
# TODO: how bad is it that this is a closure?
|
# TODO: how bad is it that this is a closure?
|
||||||
proc handle(conn: Connection): Future[void] {.closure, gcsafe.} =
|
proc handle(conn: Connection): Future[void] {.closure, gcsafe.} =
|
||||||
discard
|
s.ms.handle(conn)
|
||||||
|
|
||||||
for t in s.transports: # for each transport
|
for t in s.transports: # for each transport
|
||||||
for a in s.peerInfo.addrs:
|
for a in s.peerInfo.addrs:
|
||||||
|
|
Loading…
Reference in New Issue