Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,6 @@ require (
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/blake3 v1.4.1 // indirect
)

// TODO: remove this when it's done
replace github.com/multiformats/go-multistream => github.com/ppopth/go-multistream v0.0.0-20251120232627-f8839ce1ab11
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ github.com/multiformats/go-multicodec v0.9.1/go.mod h1:LLWNMtyV5ithSBUo3vFIMaeDy
github.com/multiformats/go-multihash v0.0.8/go.mod h1:YSLudS+Pi8NHE7o6tb3D8vrpKa63epEDmG8nTduyAew=
github.com/multiformats/go-multihash v0.2.3 h1:7Lyc8XfX/IY2jWb/gI7JP+o7JEq9hOa7BFvVU9RSh+U=
github.com/multiformats/go-multihash v0.2.3/go.mod h1:dXgKXCXjBzdscBLk9JkjINiEsCKRVch90MdaGiKsvSM=
github.com/multiformats/go-multistream v0.6.1 h1:4aoX5v6T+yWmc2raBHsTvzmFhOI8WVOer28DeBBEYdQ=
github.com/multiformats/go-multistream v0.6.1/go.mod h1:ksQf6kqHAb6zIsyw7Zm+gAuVo57Qbq84E27YlYqavqw=
github.com/multiformats/go-varint v0.0.7 h1:sWSGR+f/eu5ABZA2ZpYKBILXTTs9JWpdEM/nEGOHFS8=
github.com/multiformats/go-varint v0.0.7/go.mod h1:r8PUYw/fD/SjBCiKOoDlGF6QawOELpZAu9eioSos/OU=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
Expand Down Expand Up @@ -156,6 +154,8 @@ github.com/pion/webrtc/v4 v4.1.2 h1:mpuUo/EJ1zMNKGE79fAdYNFZBX790KE7kQQpLMjjR54=
github.com/pion/webrtc/v4 v4.1.2/go.mod h1:xsCXiNAmMEjIdFxAYU0MbB3RwRieJsegSB2JZsGN+8U=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/ppopth/go-multistream v0.0.0-20251120232627-f8839ce1ab11 h1:gMuSK7z8Tn0w9v4BEvWkpNREQ1ntq6pTJyleZdB9fXM=
github.com/ppopth/go-multistream v0.0.0-20251120232627-f8839ce1ab11/go.mod h1:sIFlNOs3fTbw+XPuWqQ0MgfxtPcVu5N8R5Xg5+H/bcE=
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
Expand Down
20 changes: 19 additions & 1 deletion p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,12 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
if err := s.SetProtocol(pref); err != nil {
return nil, err
}
lzcon := msmux.NewMSSelect(s, pref)
var lzcon msmux.LazyConn
if h.supportProtocolAbbreviation(p) {
lzcon = msmux.NewMSSelect2(s, pref, pids)
} else {
lzcon = msmux.NewMSSelect(s, pref)
}
return &streamWrapper{
Stream: s,
rw: lzcon,
Expand Down Expand Up @@ -528,6 +533,19 @@ func (h *BasicHost) preferredProtocol(p peer.ID, pids []protocol.ID) (protocol.I
return out, nil
}

func (h *BasicHost) supportProtocolAbbreviation(p peer.ID) bool {
mv, err := h.Peerstore().Get(p, "MaxMultiselectVersion")
if err != nil {
// if there is no value, assume it's not supported.
return false
}
maxVersion, ok := mv.(uint32)
if !ok {
return false
}
return maxVersion >= msmux.AbbrevSupportedMSSVersion
}

// Connect ensures there is a connection between this host and the peer with
// given peer.ID. If there is not an active connection, Connect will issue a
// h.Network.Dial, and block until a connection is open, or an error is returned.
Expand Down
8 changes: 8 additions & 0 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
DefaultTimeout = 5 * time.Second
// ServiceName is the default identify service name
ServiceName = "libp2p.identify"
// Maximum multistream-select version this implementation supports
MaxMultiselectVersion = 2

legacyIDSize = 2 * 1024
signedIDSize = 8 * 1024
Expand Down Expand Up @@ -151,6 +153,8 @@ type idService struct {
UserAgent string
ProtocolVersion string

MaxMultiselectVersion uint32

metricsTracer MetricsTracer

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

return mes
}
Expand Down Expand Up @@ -823,9 +829,11 @@ func (ids *idService) consumeMessage(mes *pb.Identify, c network.Conn, isPush bo
// get protocol versions
pv := mes.GetProtocolVersion()
av := mes.GetAgentVersion()
mv := mes.GetMaxMultiselectVersion()

ids.Host.Peerstore().Put(p, "ProtocolVersion", pv)
ids.Host.Peerstore().Put(p, "AgentVersion", av)
ids.Host.Peerstore().Put(p, "MaxMultiselectVersion", mv)

// get the key from the other side. we may not have it (no-auth transport)
ids.consumeReceivedPubKey(c, mes.PublicKey)
Expand Down
19 changes: 15 additions & 4 deletions p2p/protocol/identify/pb/identify.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions p2p/protocol/identify/pb/identify.proto
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ message Identify {
// see github.com/libp2p/go-libp2p/core/record/pb/envelope.proto and
// github.com/libp2p/go-libp2p/core/peer/pb/peer_record.proto for message definitions.
optional bytes signedPeerRecord = 8;

// maxMultiselectVersion contains the maximum multistream-select version the node supports.
// If it's absent, we assume that it's 1.
optional uint32 maxMultiselectVersion = 9;
}