mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-26 15:40:01 -07:00
28 lines
699 B
Go
28 lines
699 B
Go
// Package clientapproval XXX: implementation is broken, client ID is NOT 6 static bytes
|
|
// refer:
|
|
// - https://wiki.theory.org/BitTorrentSpecification#peer_id
|
|
// - https://github.com/webtorrent/bittorrent-peerid/blob/master/lib/utils.js
|
|
package clientapproval
|
|
|
|
import "github.com/sot-tech/mochi/bittorrent"
|
|
|
|
// ClientID represents the part of a PeerID that identifies a Peer's client
|
|
// software.
|
|
type ClientID [6]byte
|
|
|
|
// NewClientID parses a ClientID from a PeerID.
|
|
func NewClientID(pid bittorrent.PeerID) ClientID {
|
|
var cid ClientID
|
|
if pid[0] == '-' {
|
|
copy(cid[:], pid[1:7])
|
|
} else {
|
|
copy(cid[:], pid[:6])
|
|
}
|
|
|
|
return cid
|
|
}
|
|
|
|
func (cid ClientID) String() string {
|
|
return string(cid[:])
|
|
}
|