wip: switch
This commit is contained in:
parent
5eced0abee
commit
e5be1fcaee
|
@ -10,15 +10,15 @@
|
||||||
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 =
|
||||||
|
@ -26,17 +26,17 @@ proc newSwitch*(peerInfo: PeerInfo, transports: seq[Transport]): Switch =
|
||||||
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