Files
mochi/middleware/clientapproval/client_id.go
Lawrence, Rendall 61f859e3f6 (partially tested) simplify client approval m/w
* sanitize code
2023-03-23 00:34:10 +03:00

25 lines
643 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] == '-' {
cid = ClientID(pid[1:7])
} else {
cid = ClientID(pid[:6])
}
return cid
}