Skip to content

Commit

Permalink
Extract PacketWithSender to its own file
Browse files Browse the repository at this point in the history
  • Loading branch information
vposloncec committed Feb 1, 2024
1 parent 07741d9 commit 8de3a87
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions base/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ func (g *Graph) createNodes() {

// Initialize node with random values
func (g *Graph) createNode(id int) {
node := NewNode()
node.ID = NodeID(id)
node := NewNode(NodeID(id))
node.Log = g.nodeLog
g.Nodes[id] = node
}
Expand Down
9 changes: 2 additions & 7 deletions base/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ func (n NodeID) String() string {
return strconv.Itoa(int(n))
}

type PacketWithSender struct {
Packet *Packet
Sender *Node
}

type Node struct {
ID NodeID
Log *zap.SugaredLogger
Expand All @@ -38,8 +33,9 @@ type PacketLog struct {
recvNodeId NodeID
}

func NewNode() *Node {
func NewNode(id NodeID) *Node {
n := &Node{
ID: id,
MessageQueue: make(chan *PacketWithSender, 1000),
PacketHistory: make(map[PacketUUID]*PacketLog),
Reliability: NewReliability(),
Expand Down Expand Up @@ -112,7 +108,6 @@ func (n *Node) packetListener() {
n.Log.Debugf("Node %06d: Received packet %v", n.ID, packet.ID)
if n.AlreadyReceived(packet.ID) {
continue
// n.Log.Debugf("Node %06d: Packet %v already seen, skipping send", n.ID, packet.ID)
} else {
n.recordPacketReceived(packet.ID, sender.ID)
n.sendAll(packet)
Expand Down
6 changes: 6 additions & 0 deletions base/packet_with_sender.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package base

type PacketWithSender struct {
Packet *Packet
Sender *Node
}

0 comments on commit 8de3a87

Please sign in to comment.