2016-08-03 09:11:52 +02:00
|
|
|
package bittorrent
|
|
|
|
|
2016-08-04 06:33:55 +02:00
|
|
|
// ClientID represents the part of a PeerID that identifies a Peer's client
|
2016-08-03 09:11:52 +02:00
|
|
|
// software.
|
2016-08-04 06:33:55 +02:00
|
|
|
type ClientID string
|
|
|
|
|
|
|
|
// NewClientID parses a ClientID from a PeerID.
|
|
|
|
func NewClientID(peerID string) ClientID {
|
|
|
|
var clientID string
|
2016-08-03 09:11:52 +02:00
|
|
|
length := len(peerID)
|
|
|
|
if length >= 6 {
|
|
|
|
if peerID[0] == '-' {
|
|
|
|
if length >= 7 {
|
|
|
|
clientID = peerID[1:7]
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
clientID = peerID[:6]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-04 06:33:55 +02:00
|
|
|
return ClientID(clientID)
|
2016-08-03 09:11:52 +02:00
|
|
|
}
|