Skip to content

Commit ba54904

Browse files
authored
Merge pull request #34 from elecbug/v0.8
Update v0.9.0
2 parents 17eb614 + 7320df2 commit ba54904

8 files changed

Lines changed: 213 additions & 214 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ go get github.com/elecbug/netkit@latest
2121

2222
### P2P
2323

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

2626
### Extensible
2727

p2p/broadcast.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package p2p
33
// BroadcastProtocol defines the protocol used for broadcasting messages in the P2P network.
44
type BroadcastProtocol int
55

6-
var (
7-
Flooding BroadcastProtocol = 0
8-
Gossiping BroadcastProtocol = 1
9-
Custom BroadcastProtocol = 2
6+
const (
7+
Flooding BroadcastProtocol = iota
8+
Gossiping
9+
Custom
1010
)

p2p/network.go

Lines changed: 0 additions & 175 deletions
This file was deleted.

p2p/node.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func newNode(id PeerID, nodeLatency float64) *p2pNode {
4646
}
4747

4848
// eachRun starts the message handling routine for the node.
49-
func (n *p2pNode) eachRun(network *Network, wg *sync.WaitGroup, ctx context.Context) {
49+
func (n *p2pNode) eachRun(network *P2P, wg *sync.WaitGroup, ctx context.Context) {
5050
go func(ctx context.Context, wg *sync.WaitGroup) {
5151
n.alive = true
5252
wg.Done()
@@ -74,25 +74,16 @@ func (n *p2pNode) eachRun(network *Network, wg *sync.WaitGroup, ctx context.Cont
7474
if first {
7575
go func(msg Message) {
7676
time.Sleep(time.Duration(n.nodeLatency) * time.Millisecond)
77-
n.publish(network, msg)
77+
n.eachPublish(network, msg)
7878
}(msg)
7979
}
8080
}
8181
}
8282
}(ctx, wg)
8383
}
8484

85-
// // copyIDSet creates a shallow copy of a set of IDs.
86-
// func copyIDSet(src map[PeerID]struct{}) map[PeerID]struct{} {
87-
// dst := make(map[PeerID]struct{}, len(src))
88-
// for k := range src {
89-
// dst[k] = struct{}{}
90-
// }
91-
// return dst
92-
// }
93-
94-
// publish sends the message to neighbors, excluding 'exclude' and already-sent targets.
95-
func (n *p2pNode) publish(network *Network, msg Message) {
85+
// eachPublish sends the message to neighbors, excluding 'exclude' and already-sent targets.
86+
func (n *p2pNode) eachPublish(network *P2P, msg Message) {
9687
content := msg.Content
9788
protocol := msg.Protocol
9889
hopCount := msg.HopCount

0 commit comments

Comments
 (0)