Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ go get github.com/elecbug/netkit@latest

### P2P

- [`p2p`](./p2p/): Library that integrates with graph libraries to form networks and enable p2p broadcast experiments.
- [`p2p`](./p2p/): Library that integrates with graph libraries to form networks and enable P2P broadcast experiments.

### Extensible

Expand Down
8 changes: 4 additions & 4 deletions p2p/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package p2p
// BroadcastProtocol defines the protocol used for broadcasting messages in the P2P network.
type BroadcastProtocol int

var (
Flooding BroadcastProtocol = 0
Gossiping BroadcastProtocol = 1
Custom BroadcastProtocol = 2
const (
Flooding BroadcastProtocol = iota
Gossiping
Custom
)
175 changes: 0 additions & 175 deletions p2p/network.go

This file was deleted.

17 changes: 4 additions & 13 deletions p2p/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func newNode(id PeerID, nodeLatency float64) *p2pNode {
}

// eachRun starts the message handling routine for the node.
func (n *p2pNode) eachRun(network *Network, wg *sync.WaitGroup, ctx context.Context) {
func (n *p2pNode) eachRun(network *P2P, wg *sync.WaitGroup, ctx context.Context) {
go func(ctx context.Context, wg *sync.WaitGroup) {
n.alive = true
wg.Done()
Expand Down Expand Up @@ -74,25 +74,16 @@ func (n *p2pNode) eachRun(network *Network, wg *sync.WaitGroup, ctx context.Cont
if first {
go func(msg Message) {
time.Sleep(time.Duration(n.nodeLatency) * time.Millisecond)
n.publish(network, msg)
n.eachPublish(network, msg)
}(msg)
}
}
}
}(ctx, wg)
}

// // copyIDSet creates a shallow copy of a set of IDs.
// func copyIDSet(src map[PeerID]struct{}) map[PeerID]struct{} {
// dst := make(map[PeerID]struct{}, len(src))
// for k := range src {
// dst[k] = struct{}{}
// }
// return dst
// }

// publish sends the message to neighbors, excluding 'exclude' and already-sent targets.
func (n *p2pNode) publish(network *Network, msg Message) {
// eachPublish sends the message to neighbors, excluding 'exclude' and already-sent targets.
func (n *p2pNode) eachPublish(network *P2P, msg Message) {
content := msg.Content
protocol := msg.Protocol
hopCount := msg.HopCount
Expand Down
Loading