From 2f38ded0e7ffe5dc97c2341aef90a0ac61bdba9c Mon Sep 17 00:00:00 2001 From: derrandz Date: Thu, 6 Apr 2023 16:06:04 +0000 Subject: [PATCH] fix: language + export param fields --- .../adr/adr-013-bootstrap-from-previous-peers.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/adr/adr-013-bootstrap-from-previous-peers.md b/docs/adr/adr-013-bootstrap-from-previous-peers.md index aedf8ebe64..5d99f45353 100644 --- a/docs/adr/adr-013-bootstrap-from-previous-peers.md +++ b/docs/adr/adr-013-bootstrap-from-previous-peers.md @@ -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 { @@ -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) } ``` @@ -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 } } } @@ -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 } } } @@ -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. @@ -335,7 +338,6 @@ Proposed * Allows nodes to bootstrap from previously seen peers, which allows the network to gain more decentralization. -