diff --git a/swarmsim/codex/dhttracker.nim b/swarmsim/codex/dhttracker.nim index d19b438..c43150b 100644 --- a/swarmsim/codex/dhttracker.nim +++ b/swarmsim/codex/dhttracker.nim @@ -37,7 +37,7 @@ type let RandomShuffler = proc (arr: var seq[PeerDescriptor]) = discard arr.nextPermutation() -proc messageType*(T: type DHTTracker): string = "DHTTracker" +proc protocolId*(T: type DHTTracker): string = "DHTTracker" proc defaultExpiry*(T: type DHTTracker): Duration = 15.dminutes @@ -53,7 +53,7 @@ proc new*( maxPeers: maxPeers, shuffler: shuffler, peers: initOrderedTable[int, PeerDescriptor](), - messageType: DHTTracker.messageType + protocolId: DHTTracker.protocolId ) proc peers*(self: DHTTracker): seq[PeerDescriptor] = self.peers.values.toSeq() diff --git a/swarmsim/engine/network.nim b/swarmsim/engine/network.nim index 11f046e..386379e 100644 --- a/swarmsim/engine/network.nim +++ b/swarmsim/engine/network.nim @@ -16,6 +16,9 @@ type network: Network message: Message +# TODO: use distributions (or trace resampling) instead of a constant for link delay +# TODO: model link capacity and implement downloads + proc new*( T: type Network, engine: EventDrivenEngine, diff --git a/swarmsim/engine/peer.nim b/swarmsim/engine/peer.nim index 647c15a..e14c127 100644 --- a/swarmsim/engine/peer.nim +++ b/swarmsim/engine/peer.nim @@ -21,13 +21,13 @@ proc getProtocol*(self: Peer, protocolId: string): Option[Protocol] = proc deliver*(self: Peer, message: Message, engine: EventDrivenEngine, network: Network): void = - self.getProtocol(message.messageType).map( + self.getProtocol(message.protocolId).map( proc (p: Protocol): void = p.deliver(message, engine, network)) proc initPeer(self: Peer, protocols: seq[Protocol]): Peer = # XXX integer indexes or an enum would be better, but this is easier for protocol in protocols: - self.protocols[protocol.messageType] = protocol + self.protocols[protocol.protocolId] = protocol self diff --git a/swarmsim/engine/protocol.nim b/swarmsim/engine/protocol.nim index 066b516..87702b9 100644 --- a/swarmsim/engine/protocol.nim +++ b/swarmsim/engine/protocol.nim @@ -15,5 +15,5 @@ method uncheckedDeliver( proc deliver*(self: Protocol, message: Message, engine: EventDrivenEngine, network: Network): void = - assert(self.messageType == message.messageType) + assert(self.protocolId == message.protocolId) self.uncheckedDeliver(message, engine, network) diff --git a/swarmsim/engine/types.nim b/swarmsim/engine/types.nim index 73547ce..04590e5 100644 --- a/swarmsim/engine/types.nim +++ b/swarmsim/engine/types.nim @@ -30,7 +30,7 @@ type ## A `Protocol` defines a P2P protocol. It handles messages meant for it, ## keeps internal state, and may expose services to other `Protocol`s within ## the same `Peer`. - messageType*: string ## "Type" of the message accepted by this protocol. + protocolId*: string type Peer* = ref object of RootObj @@ -41,7 +41,7 @@ type Message* = ref object of RootObj ## A `Message` is a piece of data that is sent over the network. Its meaning ## is typically protocol-specific. - messageType*: string + protocolId*: string sender*: Option[Peer] = none(Peer) receiver*: Peer diff --git a/tests/codex/tdhttracker.nim b/tests/codex/tdhttracker.nim index 09c136c..3b0e2eb 100644 --- a/tests/codex/tdhttracker.nim +++ b/tests/codex/tdhttracker.nim @@ -13,7 +13,7 @@ import pkg/swarmsim/timeutils proc getPeerArray(tracker: Peer): seq[PeerDescriptor] = DHTTracker( - tracker.getProtocol(DHTTracker.messageType).get()).peers + tracker.getProtocol(DHTTracker.protocolId).get()).peers proc getPeerIdArray(tracker: Peer): seq[int] = getPeerArray(tracker).map(p => p.peerId) @@ -22,7 +22,7 @@ proc announcePeer(network: Network, tracker: Peer, peerId: int, delay: uint64 = 0) = network.send( PeerAnnouncement(receiver: tracker, - messageType: DHTTracker.messageType, peerId: peerId), + protocolId: DHTTracker.protocolId, peerId: peerId), delay.some).doAwait() suite "tracker node":