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-17 05:06:06 +02:00
|
|
|
type ClientID [6]byte
|
2016-08-04 06:33:55 +02:00
|
|
|
|
|
|
|
// NewClientID parses a ClientID from a PeerID.
|
2016-08-17 05:06:06 +02:00
|
|
|
func NewClientID(pid PeerID) ClientID {
|
|
|
|
var cid ClientID
|
|
|
|
length := len(pid)
|
2016-08-03 09:11:52 +02:00
|
|
|
if length >= 6 {
|
2016-08-17 05:06:06 +02:00
|
|
|
if pid[0] == '-' {
|
2016-08-03 09:11:52 +02:00
|
|
|
if length >= 7 {
|
2016-08-17 05:06:06 +02:00
|
|
|
copy(cid[:], pid[1:7])
|
2016-08-03 09:11:52 +02:00
|
|
|
}
|
|
|
|
} else {
|
2016-08-17 05:06:06 +02:00
|
|
|
copy(cid[:], pid[:6])
|
2016-08-03 09:11:52 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 05:06:06 +02:00
|
|
|
return cid
|
2016-08-03 09:11:52 +02:00
|
|
|
}
|