Skip to content

Commit

Permalink
fix: language + export param fields
Browse files Browse the repository at this point in the history
  • Loading branch information
derrandz committed Apr 6, 2023
1 parent e22621c commit 2f38ded
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions docs/adr/adr-013-bootstrap-from-previous-peers.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ where are `OnBlockedPeer` will be called whenever `peerTracker` blocks a peer th
+ p.onBlockedPeer(PIDToAddrInfo(pID))
}
```
We are assuming a function named `PIDToAddrInfo` that converts a `peer.ID` to a `peer.AddrInfo` struct for this example's purpose.

We are assuming a function named `PIDToAddrInfo` that converts a `peer.ID` to a `peer.AddrInfo` struct for this example's purpose.

The `peerTracker`'s constructor should be updated to accept these new event handlers:

```diff
+++ go-header/p2p/peer_tracker.go
type peerTracker struct {
Expand Down Expand Up @@ -169,8 +171,8 @@ as well as the `libhead.Exchange`'s options and construction:
// chainID is an identifier of the chain.
chainID string
+
+ onUpdatedPeers func([]peer.AddrInfo)
+ onBlockedPeer func(peer.AddrInfo)
+ OnUpdatedPeers func([]peer.AddrInfo)
+ OnBlockedPeer func(peer.AddrInfo)
}
```

Expand Down Expand Up @@ -211,13 +213,14 @@ as well as the `libhead.Exchange`'s options and construction:
```

And then define `libhead.Exchange` options to set the event handlers on the `peerTracker`:

```go
+++ go-header/p2p/options.go
func WithOnUpdatedPeers(f func([]]peer.ID)) Option[ClientParameters] {
return func(p *ClientParameters) {
switch t := any(p).(type) { //nolint:gocritic
case *PeerTrackerParameters:
p.onUpdatedPeers = f
p.OnUpdatedPeers = f
}
}
}
Expand All @@ -226,7 +229,7 @@ func WithOnBlockedPeer(f func([]]peer.ID)) Option[ClientParameters] {
return func(p *ClientParameters) {
switch t := any(p).(type) { //nolint:gocritic
case *PeerTrackerParameters:
p.onBlockedPeer = f
p.OnBlockedPeer = f
}
}
}
Expand All @@ -237,7 +240,7 @@ The event handlers to be supplied are callbacks that either:
1. Put the new peer list into the peer store
2. Remove a blocked peer from the peer store

Such callbacks are easily passable as options sat header module construction time, example:
Such callbacks are easily passable as options at header module construction time, example:

```go
// newP2PExchange constructs a new Exchange for headers.
Expand Down Expand Up @@ -335,7 +338,6 @@ Proposed

* Allows nodes to bootstrap from previously seen peers, which allows the network to gain more decentralization.


<!--
> This section does not need to be filled in at the start of the ADR, but must be completed prior to the merging of the implementation.
>
Expand Down

0 comments on commit 2f38ded

Please sign in to comment.