Skip to content

Commit

Permalink
fix: matchProtocolIDWithSemver log message and add a error log
Browse files Browse the repository at this point in the history
  • Loading branch information
kant committed Jul 17, 2024
1 parent 55736a8 commit 5ae38c2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions p2p/pkg/p2p/libp2p/libp2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,18 +281,18 @@ func ConstructProtocolID(protocolName, protocolVersion string) protocol.ID {
}

func matchProtocolIDWithSemver(
incomingProto string,
protoID string,
incomingProtoID string,
incomingProtocolName string,
supportedVersion string) (bool, error) {
// Extract the version part from the protocol ID.
parts := strings.Split(incomingProto, "/")
parts := strings.Split(incomingProtoID, "/")
if len(parts) != 3 {
return false, fmt.Errorf("invalid protocol ID: %s", protoID)
return false, fmt.Errorf("invalid protocol ID: %s", incomingProtoID)
}
protocolName := parts[1]
protocolVersion := parts[2]

if protocolName != protoID {
if protocolName != incomingProtocolName {
return false, nil
}

Expand All @@ -317,6 +317,10 @@ func (s *Service) AddStreamHandlers(streams ...p2p.StreamDesc) {
s.host.SetStreamHandlerMatch(
ConstructProtocolID(ss.Name, ss.Version),
func(p protocol.ID) bool {
parts := strings.Split(string(p), "/")
if len(parts) != 3 {
s.logger.Error("incorrect protocol ID format:", "p", string(p))
}
matched, err := matchProtocolIDWithSemver(string(p), ss.Name, ss.Version)
if err != nil {
s.logger.Error("matching protocol ID with semver", "err", err)
Expand Down

0 comments on commit 5ae38c2

Please sign in to comment.