refactor: move all dataplane code out of LocalPeer
This commit is contained in:
1 parent
e756f07cad
commit
431d04bd40
2 files changed
+46
-54
No files matched your search
@@ -27,56 +27,6 @@ func NewLocalPeer(name PeerName, nickName string, router *Router) *LocalPeer {
|
||||
return peer
|
||||
}
|
||||
|
||||
func (peer *LocalPeer) Forward(dstPeer *Peer, key PacketKey) FlowOp {
|
||||
return peer.Relay(ForwardPacketKey{
|
||||
PacketKey: key,
|
||||
SrcPeer: peer.Peer,
|
||||
DstPeer: dstPeer,
|
||||
})
|
||||
}
|
||||
|
||||
func (peer *LocalPeer) Broadcast(key PacketKey) FlowOp {
|
||||
return peer.RelayBroadcast(peer.Peer, key)
|
||||
}
|
||||
|
||||
func (peer *LocalPeer) Relay(key ForwardPacketKey) FlowOp {
|
||||
relayPeerName, found := peer.router.Routes.Unicast(key.DstPeer.Name)
|
||||
if !found {
|
||||
// Not necessarily an error as there could be a race with the
|
||||
// dst disappearing whilst the frame is in flight
|
||||
log.Println("Received packet for unknown destination:", key.DstPeer)
|
||||
return nil
|
||||
}
|
||||
|
||||
conn, found := peer.ConnectionTo(relayPeerName)
|
||||
if !found {
|
||||
// Again, could just be a race, not necessarily an error
|
||||
log.Println("Unable to find connection to relay peer", relayPeerName)
|
||||
return nil
|
||||
}
|
||||
|
||||
return conn.(*LocalConnection).Forward(key)
|
||||
}
|
||||
|
||||
func (peer *LocalPeer) RelayBroadcast(srcPeer *Peer, key PacketKey) FlowOp {
|
||||
nextHops := peer.router.Routes.Broadcast(srcPeer.Name)
|
||||
if len(nextHops) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
op := NewMultiFlowOp(true)
|
||||
|
||||
for _, conn := range peer.ConnectionsTo(nextHops) {
|
||||
op.Add(conn.(*LocalConnection).Forward(ForwardPacketKey{
|
||||
PacketKey: key,
|
||||
SrcPeer: srcPeer,
|
||||
DstPeer: conn.Remote(),
|
||||
}))
|
||||
}
|
||||
|
||||
return op
|
||||
}
|
||||
|
||||
func (peer *LocalPeer) Connections() ConnectionSet {
|
||||
connections := make(ConnectionSet)
|
||||
peer.RLock()
|
||||
|
||||
Reference in new issue
Block a user