Skip to content

Commit 15685d7

Browse files
committed
identify: have MaxMultiselectVersion
1 parent aefe389 commit 15685d7

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

p2p/protocol/identify/id.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const (
4444
DefaultTimeout = 5 * time.Second
4545
// ServiceName is the default identify service name
4646
ServiceName = "libp2p.identify"
47+
// Maximum multistream-select this implementation supports
48+
MaxMultiselectVersion = 2
4749

4850
legacyIDSize = 2 * 1024
4951
signedIDSize = 8 * 1024
@@ -151,6 +153,8 @@ type idService struct {
151153
UserAgent string
152154
ProtocolVersion string
153155

156+
MaxMultiselectVersion uint32
157+
154158
metricsTracer MetricsTracer
155159

156160
setupCompleted chan struct{} // is closed when Start has finished setting up
@@ -204,6 +208,7 @@ func NewIDService(h host.Host, opts ...Option) (*idService, error) {
204208
Host: h,
205209
UserAgent: userAgent,
206210
ProtocolVersion: cfg.protocolVersion,
211+
MaxMultiselectVersion: MaxMultiselectVersion,
207212
ctx: ctx,
208213
ctxCancel: cancel,
209214
conns: make(map[network.Conn]entry),
@@ -679,6 +684,7 @@ func (ids *idService) createBaseIdentifyResponse(conn network.Conn, snapshot *id
679684
// set protocol versions
680685
mes.ProtocolVersion = &ids.ProtocolVersion
681686
mes.AgentVersion = &ids.UserAgent
687+
mes.MaxMultiselectVersion = &ids.MaxMultiselectVersion
682688

683689
return mes
684690
}
@@ -823,9 +829,11 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo
823829
// get protocol versions
824830
pv := mes.GetProtocolVersion()
825831
av := mes.GetAgentVersion()
832+
mv := mes.GetMaxMultiselectVersion()
826833

827834
ids.Host.Peerstore().Put(p, "ProtocolVersion", pv)
828835
ids.Host.Peerstore().Put(p, "AgentVersion", av)
836+
ids.Host.Peerstore().Put(p, "MaxMultiselectVersion", mv)
829837

830838
// get the key from the other side. we may not have it (no-auth transport)
831839
ids.consumeReceivedPubKey(c, mes.PublicKey)

p2p/protocol/identify/pb/identify.pb.go

Lines changed: 15 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

p2p/protocol/identify/pb/identify.proto

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ message Identify {
3535
// see github.com/libp2p/go-libp2p/core/record/pb/envelope.proto and
3636
// github.com/libp2p/go-libp2p/core/peer/pb/peer_record.proto for message definitions.
3737
optional bytes signedPeerRecord = 8;
38+
39+
// maxMultiselectVersion contains the maximum multistream-select version the node supports.
40+
// If it's absent, we assume that it's 1.
41+
optional uint32 maxMultiselectVersion = 9;
3842
}

0 commit comments

Comments
 (0)