2021-07-29 12:41:37 +00:00
|
|
|
package protocol
|
|
|
|
|
2023-02-16 16:17:52 +00:00
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/libp2p/go-libp2p/core/protocol"
|
|
|
|
)
|
2021-07-29 12:41:37 +00:00
|
|
|
|
2021-10-09 18:18:53 +00:00
|
|
|
// FulltextMatch is the default matching function used for checking if a peer
|
|
|
|
// supports a protocol or not
|
2021-07-29 12:41:37 +00:00
|
|
|
func FulltextMatch(expectedProtocol string) func(string) bool {
|
|
|
|
return func(receivedProtocol string) bool {
|
|
|
|
return receivedProtocol == expectedProtocol
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-09 18:18:53 +00:00
|
|
|
// PrefixTextMatch is a matching function used for checking if a peer's
|
|
|
|
// supported protocols begin with a particular prefix
|
2023-02-16 16:17:52 +00:00
|
|
|
func PrefixTextMatch(prefix string) func(protocol.ID) bool {
|
|
|
|
return func(receivedProtocol protocol.ID) bool {
|
|
|
|
return strings.HasPrefix(string(receivedProtocol), prefix)
|
2021-07-29 12:41:37 +00:00
|
|
|
}
|
|
|
|
}
|