identify: remove snapshot handling
This commit is contained in:
parent
56078a18f7
commit
5095f44da2
|
@ -400,10 +400,7 @@ func (ids *idService) sendIdentifyResp(s network.Stream) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ph.snapshotMu.RLock()
|
ids.writeChunkedIdentifyMsg(c, s)
|
||||||
snapshot := ph.snapshot
|
|
||||||
ph.snapshotMu.RUnlock()
|
|
||||||
ids.writeChunkedIdentifyMsg(c, snapshot, s)
|
|
||||||
log.Debugf("%s sent message to %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr())
|
log.Debugf("%s sent message to %s %s", ID, c.RemotePeer(), c.RemoteMultiaddr())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -471,7 +468,8 @@ func (ids *idService) getSnapshot() *identifySnapshot {
|
||||||
return snapshot
|
return snapshot
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ids *idService) writeChunkedIdentifyMsg(c network.Conn, snapshot *identifySnapshot, s network.Stream) error {
|
func (ids *idService) writeChunkedIdentifyMsg(c network.Conn, s network.Stream) error {
|
||||||
|
snapshot := ids.getSnapshot()
|
||||||
mes := ids.createBaseIdentifyResponse(c, snapshot)
|
mes := ids.createBaseIdentifyResponse(c, snapshot)
|
||||||
sr := ids.getSignedRecord(snapshot)
|
sr := ids.getSignedRecord(snapshot)
|
||||||
mes.SignedPeerRecord = sr
|
mes.SignedPeerRecord = sr
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p/core/network"
|
"github.com/libp2p/go-libp2p/core/network"
|
||||||
|
@ -29,23 +28,15 @@ type peerHandler struct {
|
||||||
|
|
||||||
pid peer.ID
|
pid peer.ID
|
||||||
|
|
||||||
snapshotMu sync.RWMutex
|
|
||||||
snapshot *identifySnapshot
|
|
||||||
|
|
||||||
pushCh chan struct{}
|
pushCh chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newPeerHandler(pid peer.ID, ids *idService) *peerHandler {
|
func newPeerHandler(pid peer.ID, ids *idService) *peerHandler {
|
||||||
ph := &peerHandler{
|
return &peerHandler{
|
||||||
ids: ids,
|
ids: ids,
|
||||||
pid: pid,
|
pid: pid,
|
||||||
|
|
||||||
snapshot: ids.getSnapshot(),
|
|
||||||
|
|
||||||
pushCh: make(chan struct{}, 1),
|
pushCh: make(chan struct{}, 1),
|
||||||
}
|
}
|
||||||
|
|
||||||
return ph
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// start starts a handler. This may only be called on a stopped handler, and must
|
// start starts a handler. This may only be called on a stopped handler, and must
|
||||||
|
@ -63,7 +54,10 @@ func (ph *peerHandler) start(ctx context.Context, onExit func()) {
|
||||||
ctx, cancel := context.WithCancel(ctx)
|
ctx, cancel := context.WithCancel(ctx)
|
||||||
ph.cancel = cancel
|
ph.cancel = cancel
|
||||||
|
|
||||||
go ph.loop(ctx, onExit)
|
go func() {
|
||||||
|
ph.loop(ctx)
|
||||||
|
onExit()
|
||||||
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
// stop stops a handler. This may not be called concurrently with any
|
// stop stops a handler. This may not be called concurrently with any
|
||||||
|
@ -77,9 +71,7 @@ func (ph *peerHandler) stop() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// per peer loop for pushing updates
|
// per peer loop for pushing updates
|
||||||
func (ph *peerHandler) loop(ctx context.Context, onExit func()) {
|
func (ph *peerHandler) loop(ctx context.Context) {
|
||||||
defer onExit()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
// our listen addresses have changed, send an IDPush.
|
// our listen addresses have changed, send an IDPush.
|
||||||
|
@ -104,11 +96,7 @@ func (ph *peerHandler) sendPush(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
defer dp.Close()
|
defer dp.Close()
|
||||||
|
|
||||||
snapshot := ph.ids.getSnapshot()
|
if err := ph.ids.writeChunkedIdentifyMsg(dp.Conn(), dp); err != nil {
|
||||||
ph.snapshotMu.Lock()
|
|
||||||
ph.snapshot = snapshot
|
|
||||||
ph.snapshotMu.Unlock()
|
|
||||||
if err := ph.ids.writeChunkedIdentifyMsg(dp.Conn(), snapshot, dp); err != nil {
|
|
||||||
_ = dp.Reset()
|
_ = dp.Reset()
|
||||||
return fmt.Errorf("failed to send push message: %w", err)
|
return fmt.Errorf("failed to send push message: %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue