tracker/bittorrent/client_id.go

23 lines
407 B
Go
Raw Normal View History

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