Documentation ¶
Overview ¶
Package ptp is a generated protocol buffer package.
It is generated from these files:
dht.proto
It has these top-level messages:
DHTPacket
Index ¶
- Constants
- Variables
- func CheckPermissions() bool
- func FilterInterface(infName, infIP string) bool
- func GenerateMAC() (string, net.HardwareAddr)
- func GenerateToken() string
- func GetConfigurationTool() string
- func GetDeviceBase() string
- func InitErrors()
- func InitPlatform()
- func IsInterfaceLocal(ip net.IP) bool
- func Log(level LogLevel, format string, v ...interface{})
- func SetMinLogLevel(level LogLevel)
- func SetSyslogSocket(socket string)
- func SetupPlatform(remove bool)
- func StringifyState(state PeerState) string
- func Syslog(level LogLevel, format string, v ...interface{})
- type ARPPacket
- type Configuration
- type Crypto
- type CryptoKey
- type DHTClient
- func (dht *DHTClient) Close() error
- func (dht *DHTClient) Connect(ipList []net.IP, proxyList []*proxyServer) error
- func (dht *DHTClient) Init(hash string) error
- func (dht *DHTClient) RegisterProxy(ip net.IP, port int) error
- func (dht *DHTClient) ReportLoad(clientsNum int) error
- func (dht *DHTClient) WaitID() error
- type DHTPacket
- func (*DHTPacket) Descriptor() ([]byte, []int)
- func (m *DHTPacket) GetArguments() []string
- func (m *DHTPacket) GetData() string
- func (m *DHTPacket) GetExtra() string
- func (m *DHTPacket) GetId() string
- func (m *DHTPacket) GetInfohash() string
- func (m *DHTPacket) GetPayload() []byte
- func (m *DHTPacket) GetProxies() []string
- func (m *DHTPacket) GetQuery() string
- func (m *DHTPacket) GetType() DHTPacketType
- func (m *DHTPacket) GetVersion() int32
- func (*DHTPacket) ProtoMessage()
- func (m *DHTPacket) Reset()
- func (m *DHTPacket) String() string
- type DHTPacketType
- type ErrorType
- type Forwarder
- type ListOperation
- type LogLevel
- type MessageHandler
- type MsgType
- type Network
- func (uc *Network) Addr() *net.UDPAddr
- func (uc *Network) Disposed() bool
- func (uc *Network) GetPort() int
- func (uc *Network) Init(host string, port int) error
- func (uc *Network) KeepAlive(addr *net.UDPAddr)
- func (uc *Network) Listen(receivedCallback UDPReceivedCallback)
- func (uc *Network) SendMessage(msg *P2PMessage, dstAddr *net.UDPAddr) (int, error)
- func (uc *Network) SendRawBytes(bytes []byte, dstAddr *net.UDPAddr) (int, error)
- func (uc *Network) Stop()
- type NetworkPeer
- type NetworkPeerState
- type OperatingMode
- type Operation
- type P2PMessage
- type P2PMessageHeader
- type Packet
- type PacketHandlerCallback
- type PacketType
- type PeerEndpoint
- type PeerHandshake
- type PeerIP
- type PeerList
- func (l *PeerList) Delete(id string)
- func (l *PeerList) Get() map[string]*NetworkPeer
- func (l *PeerList) GetEndpointAndProxy(mac string) (*net.UDPAddr, uint16, error)
- func (l *PeerList) GetID(ip string) (string, error)
- func (l *PeerList) GetPeer(id string) *NetworkPeer
- func (l *PeerList) Init()
- func (l *PeerList) Length() int
- func (l *PeerList) RunPeer(id string, p *PeerToPeer)
- func (l *PeerList) Update(id string, peer *NetworkPeer)
- type PeerState
- type PeerStats
- type PeerToPeer
- func (p *PeerToPeer) AssignInterface(interfaceName string) error
- func (p *PeerToPeer) Close() error
- func (p *PeerToPeer) CreateMessage(msgType MsgType, payload []byte, proto uint16, encrypt bool) (*P2PMessage, error)
- func (p *PeerToPeer) FindNetworkAddresses()
- func (p *PeerToPeer) GenerateDeviceName(i int) string
- func (p *PeerToPeer) HandleBadTun(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) HandleIntroMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) HandleIntroRequestMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) HandleNotEncryptedMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) HandleP2PMessage(count int, srcAddr *net.UDPAddr, err error, rcvBytes []byte)
- func (p *PeerToPeer) HandlePingMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) HandleProxyMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) HandleXpeerPingMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
- func (p *PeerToPeer) Init()
- func (p *PeerToPeer) IsDeviceExists(name string) bool
- func (p *PeerToPeer) IsIPv4(ip string) bool
- func (p *PeerToPeer) ListenInterface()
- func (p *PeerToPeer) ParseIntroString(intro string) (*PeerHandshake, error)
- func (p *PeerToPeer) PrepareInterfaces(ip, interfaceName string) error
- func (p *PeerToPeer) PrepareIntroductionMessage(id, endpoint string) *P2PMessage
- func (p *PeerToPeer) ReadDHT()
- func (p *PeerToPeer) ReportIP(ipAddress, mac, device string) (net.IP, net.IPMask, error)
- func (p *PeerToPeer) RequestIP(mac, device string) (net.IP, net.IPMask, error)
- func (p *PeerToPeer) Run()
- func (p *PeerToPeer) SendTo(dst net.HardwareAddr, msg *P2PMessage) (int, error)
- func (p *PeerToPeer) WriteToDevice(b []byte, proto uint16, truncated bool)
- type ProxyManager
- type RemotePeerState
- type StateHandlerCallback
- type TAP
- type TAPLinux
- func (t *TAPLinux) Close() error
- func (t *TAPLinux) Configure() error
- func (t *TAPLinux) GetBasename() string
- func (t *TAPLinux) GetHardwareAddress() net.HardwareAddr
- func (t *TAPLinux) GetIP() net.IP
- func (t *TAPLinux) GetMask() net.IPMask
- func (t *TAPLinux) GetName() string
- func (t *TAPLinux) Init(name string) error
- func (t *TAPLinux) IsConfigured() bool
- func (t *TAPLinux) MarkConfigured()
- func (t *TAPLinux) Open() error
- func (t *TAPLinux) ReadPacket() (*Packet, error)
- func (t *TAPLinux) Run()
- func (t *TAPLinux) SetHardwareAddress(mac net.HardwareAddr)
- func (t *TAPLinux) SetIP(ip net.IP)
- func (t *TAPLinux) SetMask(mask net.IPMask)
- func (t *TAPLinux) SetName(name string)
- func (t *TAPLinux) WritePacket(packet *Packet) error
- type TError
- type UDPReceivedCallback
Constants ¶
const ( MagicCookie uint16 = 0xabcd HeaderSize int = 10 )
Constants
const ( EthPacketSize int = 512 PacketPARCUniversal PacketType = 512 PacketIPv4 PacketType = 2048 PacketARP PacketType = 2054 PacketRARP PacketType = 32821 Packet8021Q PacketType = 33024 PacketIPv6 PacketType = 34525 PacketPPPoEDiscovery PacketType = 34915 PacketPPPoESession PacketType = 34916 PacketLLDP PacketType = 35020 )
Packet Types
const ( ConfigDir string = "/usr/local/etc" DefaultMTU int = 1376 )
Constants
const ( MsgTypeString MsgType = 0 // String MsgTypeIntro = 1 // Introduction packet MsgTypeIntroReq = 2 // Request for introduction packet MsgTypeNenc = 3 // Not encrypted message MsgTypeEnc = 4 // Encrypted message MsgTypePing = 5 // Internal ping message for Proxies MsgTypeXpeerPing = 6 // Crosspeer ping message MsgTypeTest = 7 // Packet tests established connection MsgTypeProxy = 8 // Information about proxy (forwarder) MsgTypeBadTun = 9 // Notifies about dead tunnel MsgTypeConf = 10 // Confirmation )
Internal network packet type
const ( DhtCmdConn string = "conn" DhtCmdFrwd string = "frwd" DhtCmdFind string = "find" DhtCmdNode string = "node" DhtCmdPing string = "ping" DhtCmdRegProxy string = "regcp" DhtCmdBadProxy string = "badcp" DhtCmdProxy string = "cp" DhtCmdNotify string = "notify" DhtCmdLoad string = "load" DhtCmdStop string = "stop" DhtCmdUnknown string = "unk" DhtCmdDhcp string = "dhcp" DhtCmdError string = "error" DhtCmdUnsupported string = "unsupported" DhtCmdState string = "state" )
List of commands used in DHT
const ( PeerStateInit PeerState = 1 // Peer has been added recently. PeerStateRequestedIP = 2 // We know ID of a peer, but don't know it's IPs PeerStateRequestingProxy = 3 // Requesting proxies for this peer PeerStateWaitingForProxy = 4 // Waiting for proxies PeerStateWaitingToConnect = 5 // Waiting for other peer to start establishing connection PeerStateConnecting = 6 // Trying to establish connection PeerStateConnected = 7 // Connected, handshaked and operating normally PeerStateDisconnect = 8 // We're disconnecting PeerStateStop = 9 // Peer has been stopped and now can be removed from list of peers PeerStateCooldown = 10 // Peer is in cooldown mode )
Peer state
const ( DHTMaxRetries int = 10 DHCPMaxRetries int = 10 PeerPingTimeout time.Duration = time.Second * 1 WaitProxyTimeout time.Duration = time.Second * 5 HandshakeProxyTimeout time.Duration = time.Second * 3 )
Timeouts and retries
const DHTBufferSize = 1024
DHTBufferSize is a size of DHT buffer
const ( // DhtErrorUnsupported - Unsupported version DhtErrorUnsupported string = "unsupported" )
const (
MaximumInterfaceNameLength int = 12
)
const PacketVersion int32 = 20005
PacketVersion is a version of packet used in DHT communication
Variables ¶
var ( // ErrInvalidHardwareAddr is returned when one or more invalid hardware // addresses are passed to NewPacket. ErrInvalidHardwareAddr = errors.New("invalid hardware address") // ErrInvalidIP is returned when one or more invalid IPv4 addresses are // passed to NewPacket. ErrInvalidIP = errors.New("invalid IPv4 address") // PacketID is a ID of the received packet PacketID uint16 )
var ActiveInterfaces []net.IP
ActiveInterfaces is a global (daemon-wise) list of reserved IP addresses
var DHTPacketType_name = map[int32]string{
0: "Undefined",
1: "Connect",
2: "Forward",
3: "Find",
4: "Node",
5: "Ping",
6: "RegisterProxy",
7: "RequestProxy",
8: "ReportProxy",
9: "BadProxy",
10: "Proxy",
11: "Notify",
12: "ReportLoad",
13: "Stop",
14: "Unknown",
15: "DHCP",
16: "Error",
17: "Unsupported",
18: "State",
}
var DHTPacketType_value = map[string]int32{
"Undefined": 0,
"Connect": 1,
"Forward": 2,
"Find": 3,
"Node": 4,
"Ping": 5,
"RegisterProxy": 6,
"RequestProxy": 7,
"ReportProxy": 8,
"BadProxy": 9,
"Proxy": 10,
"Notify": 11,
"ReportLoad": 12,
"Stop": 13,
"Unknown": 14,
"DHCP": 15,
"Error": 16,
"Unsupported": 17,
"State": 18,
}
var ( // ErrorList stores known errors ErrorList map[ErrorType]error )
var SupportedVersion = [...]int32{20005, 200006}
SupportedVersion is a list of versions supported by DHT server
Functions ¶
func CheckPermissions ¶
func CheckPermissions() bool
CheckPermissions validates platform specific permissions to run TUNTAP utilities
func FilterInterface ¶
FilterInterface will return true if this interface needs to be filtered out
func GenerateMAC ¶
func GenerateMAC() (string, net.HardwareAddr)
GenerateMAC generates a MAC address for a new interface
func GenerateToken ¶
func GenerateToken() string
GenerateToken produces UUID string that will be used during handshake with DHT server. Since we don't have an ID on start - we will use token and wait from DHT server to respond with ID and our Token, so later we will replace Token with received ID
func GetConfigurationTool ¶
func GetConfigurationTool() string
GetConfigurationTool function will return path to configuration tool on specific platform
func IsInterfaceLocal ¶
IsInterfaceLocal will return true if specified IP is in list of local network interfaces
func SetMinLogLevel ¶
func SetMinLogLevel(level LogLevel)
SetMinLogLevel sets a minimal logging level
func SetSyslogSocket ¶
func SetSyslogSocket(socket string)
SetSyslogSocket sets an adders of the syslog server
func SetupPlatform ¶
func SetupPlatform(remove bool)
SetupPlatform runs platform specific preparations during p2p daemon creation
func StringifyState ¶
StringifyState extracts human-readable word that represents a peer status
Types ¶
type ARPPacket ¶
type ARPPacket struct { // HardwareType specifies an IANA-assigned hardware type, as described // in RFC 826. HardwareType uint16 // ProtocolType specifies the internetwork protocol for which the ARP // request is intended. Typically, this is the IPv4 EtherType. ProtocolType uint16 // HardwareAddrLength specifies the length of the sender and target // hardware addresses included in a Packet. HardwareAddrLength uint8 // IPLength specifies the length of the sender and target IPv4 addresses // included in a Packet. IPLength uint8 // Operation specifies the ARP operation being performed, such as request // or reply. Operation Operation // SenderHardwareAddr specifies the hardware address of the sender of this // Packet. SenderHardwareAddr net.HardwareAddr // SenderIP specifies the IPv4 address of the sender of this Packet. SenderIP net.IP // TargetHardwareAddr specifies the hardware address of the target of this // Packet. TargetHardwareAddr net.HardwareAddr // TargetIP specifies the IPv4 address of the target of this Packet. TargetIP net.IP }
ARPPacket represents an ARP packet
func (*ARPPacket) MarshalBinary ¶
MarshalBinary allocates a byte slice containing the data from a Packet.
MarshalBinary never returns an error.
func (*ARPPacket) NewPacket ¶
func (p *ARPPacket) NewPacket(op Operation, srcHW net.HardwareAddr, srcIP net.IP, dstHW net.HardwareAddr, dstIP net.IP) (*ARPPacket, error)
NewPacket creates new ARP packet
func (*ARPPacket) UnmarshalARP ¶
UnmarshalARP unmarshals ARP header
type Configuration ¶
type Configuration struct { IPTool string `yaml:"iptool"` // Network interface configuration tool AddTap string `yaml:"addtap"` // Path to addtap.bat InfFile string `yaml:"inffile"` // Path to deltap.bat }
func (*Configuration) GetAddTap ¶
func (y *Configuration) GetAddTap() string
func (*Configuration) GetIPTool ¶
func (y *Configuration) GetIPTool() string
func (*Configuration) GetInfFile ¶
func (y *Configuration) GetInfFile() string
func (*Configuration) Read ¶
func (y *Configuration) Read() error
type Crypto ¶
Crypto is a object used by crypto subsystem
func (Crypto) EnrichKeyValues ¶
EnrichKeyValues update information about current and feature keys
func (Crypto) ReadKeysFromFile ¶
ReadKeysFromFile read a file stored in a file system and extracts keys to be used
type CryptoKey ¶
type CryptoKey struct { TTLConfig string `yaml:"ttl"` KeyConfig string `yaml:"key"` Until time.Time Key []byte }
CryptoKey represents a key and it's expiration date
type DHTClient ¶
type DHTClient struct { Routers string // Comma-separated list of bootstrap nodes NetworkHash string // Saved network hash ID string // Current instance ID FailedRouters []string // List of routes that we failed to connect to Connections []*net.TCPConn // TCP connections to bootstrap nodes LocalPort int // UDP port number used by this instance RemotePort int // UDP port number reported by echo server Forwarders []Forwarder // List of worwarders TCPCallbacks map[DHTPacketType]dhtCallback // Callbacks for incoming packets Mode OperatingMode // DHT Client mode ??? IPList []net.IP // List of network active interfaces IP net.IP // IP of local interface received from DHCP or specified manually Network *net.IPNet // Network information about current network. Used to inform p2p about mask for interface Connected bool // Whether connection with bootstrap nodes established or not //isShutdown bool // Whether DHT shutting down or not LastUpdate time.Time // When last `find` packet was sent OutboundIP net.IP // Outbound IP ListenerIsRunning bool // True if listener is runnning IncomingData chan *DHTPacket OutgoingData chan *DHTPacket }
DHTClient is a main structure of a DHT client
func (*DHTClient) Close ¶
Close will close all connections and switch DHT object to shutdown mode, which will terminate every loop/goroutine
func (*DHTClient) RegisterProxy ¶
RegisterProxy will register current node as a proxy on bootstrap node
func (*DHTClient) ReportLoad ¶
ReportLoad will send amount of tunnels created on particular proxy
type DHTPacket ¶
type DHTPacket struct { Type DHTPacketType `protobuf:"varint,1,opt,name=type,enum=main.DHTPacketType" json:"type,omitempty"` Id string `protobuf:"bytes,2,opt,name=id" json:"id,omitempty"` Infohash string `protobuf:"bytes,3,opt,name=infohash" json:"infohash,omitempty"` Data string `protobuf:"bytes,4,opt,name=data" json:"data,omitempty"` Query string `protobuf:"bytes,5,opt,name=query" json:"query,omitempty"` Arguments []string `protobuf:"bytes,6,rep,name=arguments" json:"arguments,omitempty"` Proxies []string `protobuf:"bytes,7,rep,name=proxies" json:"proxies,omitempty"` Extra string `protobuf:"bytes,8,opt,name=extra" json:"extra,omitempty"` Payload []byte `protobuf:"bytes,9,opt,name=payload,proto3" json:"payload,omitempty"` Version int32 `protobuf:"varint,10,opt,name=version" json:"version,omitempty"` }
func (*DHTPacket) Descriptor ¶
func (*DHTPacket) GetArguments ¶
func (*DHTPacket) GetInfohash ¶
func (*DHTPacket) GetPayload ¶
func (*DHTPacket) GetProxies ¶
func (*DHTPacket) GetType ¶
func (m *DHTPacket) GetType() DHTPacketType
func (*DHTPacket) GetVersion ¶
func (*DHTPacket) ProtoMessage ¶
func (*DHTPacket) ProtoMessage()
type DHTPacketType ¶
type DHTPacketType int32
const ( DHTPacketType_Undefined DHTPacketType = 0 DHTPacketType_Connect DHTPacketType = 1 DHTPacketType_Forward DHTPacketType = 2 DHTPacketType_Find DHTPacketType = 3 DHTPacketType_Node DHTPacketType = 4 DHTPacketType_Ping DHTPacketType = 5 DHTPacketType_RegisterProxy DHTPacketType = 6 DHTPacketType_RequestProxy DHTPacketType = 7 DHTPacketType_ReportProxy DHTPacketType = 8 DHTPacketType_BadProxy DHTPacketType = 9 DHTPacketType_Proxy DHTPacketType = 10 DHTPacketType_Notify DHTPacketType = 11 DHTPacketType_ReportLoad DHTPacketType = 12 DHTPacketType_Stop DHTPacketType = 13 DHTPacketType_Unknown DHTPacketType = 14 DHTPacketType_DHCP DHTPacketType = 15 DHTPacketType_Error DHTPacketType = 16 DHTPacketType_Unsupported DHTPacketType = 17 DHTPacketType_State DHTPacketType = 18 )
func (DHTPacketType) EnumDescriptor ¶
func (DHTPacketType) EnumDescriptor() ([]byte, []int)
func (DHTPacketType) String ¶
func (x DHTPacketType) String() string
type ErrorType ¶
type ErrorType string
ErrorType is a type of an error
const ( ErrUnknownError ErrorType = "unknownerror" ErrIncopatibleVersion ErrorType = "unsupported" ErrMalformedHandshake ErrorType = "badhandshake" ErrPortParseFailed ErrorType = "badport" ErrBadUDPAddr ErrorType = "badudpaddr" ErrBadIDReceived ErrorType = "badid" ErrBadDHCPData ErrorType = "baddhcp" )
Types of errors
type ListOperation ¶
type ListOperation int
ListOperation will specify which operation is performed on peer list
const ( OperateDelete ListOperation = 0 // Delete entry from map OperateUpdate ListOperation = 1 // Add/Update entry in map )
List operations
type MessageHandler ¶
type MessageHandler func(message *P2PMessage, srcAddr *net.UDPAddr)
MessageHandler is a messages callback
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network is a network subsystem
func (*Network) KeepAlive ¶
KeepAlive will send keep alive packet periodically to keep UDP port bind
func (*Network) Listen ¶
func (uc *Network) Listen(receivedCallback UDPReceivedCallback)
Listen is a main listener of a network traffic
func (*Network) SendMessage ¶
SendMessage sends message over network
func (*Network) SendRawBytes ¶
SendRawBytes sends bytes over network
type NetworkPeer ¶
type NetworkPeer struct { ID string // ID of a peer Endpoint *net.UDPAddr // Endpoint address of a peer. TODO: Make this net.UDPAddr KnownIPs []*net.UDPAddr // List of IP addresses that accepts connection on peer Proxies []*net.UDPAddr // List of proxies of this peer PeerLocalIP net.IP // IP of peers interface. TODO: Rename to IP PeerHW net.HardwareAddr // Hardware address of peer interface. TODO: Rename to Mac State PeerState // State of a peer on our end RemoteState PeerState // State of remote peer LastContact time.Time // Last ping with this peer PingCount uint8 // Number of pings messages sent without response LastError string // Test of last error occured during state execution ConnectionAttempts uint8 // How many times we tried to connect Running bool // Whether peer is running or not EndpointsHeap []*PeerEndpoint // List of all endpoints // EndpointsActive []PeerEndpoint // List of active endpoints EndpointsLock sync.RWMutex // Mutex for endpoints operations LastFind time.Time // Moment when we got this peer from DHT LastPunch time.Time // Last time we run hole punch Stat PeerStats // Peer statistics // contains filtered or unexported fields }
NetworkPeer represents a peer
func (*NetworkPeer) BumpEndpoint ¶
func (np *NetworkPeer) BumpEndpoint(epAddr string)
func (*NetworkPeer) RequestForwarder ¶
func (np *NetworkPeer) RequestForwarder(ptpc *PeerToPeer)
RequestForwarder sends a request for a proxy with DHT client
func (*NetworkPeer) SetState ¶
func (np *NetworkPeer) SetState(state PeerState, ptpc *PeerToPeer)
SetState modify local state of peer
type NetworkPeerState ¶
NetworkPeerState represents a state for remote peers
type OperatingMode ¶
type OperatingMode int
OperatingMode - Mode in which DHT client is operating
const ( DHTModeClient OperatingMode = 1 DHTModeProxy OperatingMode = 2 )
Possible operating modes
type Operation ¶
type Operation uint16
Operation determines whether operation is a request or a reply
type P2PMessage ¶
type P2PMessage struct { Header *P2PMessageHeader Data []byte }
P2PMessage is a cross-peer message packet
func CreateMessageStatic ¶
func CreateMessageStatic(msgType MsgType, payload []byte) (*P2PMessage, error)
CreateMessageStatic is a static method for a P2P Message
func P2PMessageFromBytes ¶
func P2PMessageFromBytes(bytes []byte) (*P2PMessage, error)
P2PMessageFromBytes extract a payload from received packet
func (*P2PMessage) Serialize ¶
func (v *P2PMessage) Serialize() []byte
Serialize constructs a P2P message
type P2PMessageHeader ¶
type P2PMessageHeader struct { Magic uint16 Type uint16 Length uint16 SerializedLen uint16 NetProto uint16 }
P2PMessageHeader is header used in cross-peer packets
func P2PMessageHeaderFromBytes ¶
func P2PMessageHeaderFromBytes(bytes []byte) (*P2PMessageHeader, error)
P2PMessageHeaderFromBytes extracts message header from received packet
func (*P2PMessageHeader) Serialize ¶
func (v *P2PMessageHeader) Serialize() []byte
Serialize does a header serialization
type PacketHandlerCallback ¶
PacketHandlerCallback represents a callback function for each packet type
type PeerEndpoint ¶
PeerEndpoint reprsents a UDP address endpoint that instance may use for connection with a peer
type PeerHandshake ¶
type PeerHandshake struct { ID string IP net.IP HardwareAddr net.HardwareAddr Endpoint *net.UDPAddr }
PeerHandshake holds handshake information received from peer
type PeerList ¶
type PeerList struct {
// contains filtered or unexported fields
}
PeerList is for handling list of peers with all mappings
func (*PeerList) Get ¶
func (l *PeerList) Get() map[string]*NetworkPeer
Get returns copy of map with all peers
func (*PeerList) GetEndpointAndProxy ¶
GetEndpointAndProxy returns endpoint address and proxy id
func (*PeerList) GetPeer ¶
func (l *PeerList) GetPeer(id string) *NetworkPeer
GetPeer returns single peer by id
func (*PeerList) RunPeer ¶
func (l *PeerList) RunPeer(id string, p *PeerToPeer)
RunPeer should be called once on each peer when added to list
func (*PeerList) Update ¶
func (l *PeerList) Update(id string, peer *NetworkPeer)
Update will append/edit peer in list
type PeerStats ¶
type PeerStats struct {
// contains filtered or unexported fields
}
PeerStats represents different peer statistics
type PeerToPeer ¶
type PeerToPeer struct { Config Configuration // Network interface configuration tool UDPSocket *Network // Peer-to-peer interconnection socket LocalIPs []net.IP // List of IPs available in the system Dht *DHTClient // DHT Client Crypter Crypto // Cryptography subsystem Shutdown bool // Set to true when instance in shutdown mode ForwardMode bool // Skip local peer discovery ReadyToStop bool // Set to true when instance is ready to stop MessageHandlers map[uint16]MessageHandler // Callbacks for network packets PacketHandlers map[PacketType]PacketHandlerCallback // Callbacks for packets received by TAP interface PeersLock sync.Mutex // Lock for peers map Hash string // Infohash for this instance Routers string // Comma-separated list of Bootstrap nodes Interface TAP // TAP Interface Peers *PeerList // Known peers HolePunching sync.Mutex // Mutex for hole punching sync ProxyManager *ProxyManager // Proxy manager // contains filtered or unexported fields }
PeerToPeer - Main structure
func New ¶
func New(argIP, argMac, argDev, argDirect, argHash, argDht, argKeyfile, argKey, argTTL, argLog string, fwd bool, port int, ignoreIPs []string, outboundIP net.IP) *PeerToPeer
New is an entry point of a P2P library.
func (*PeerToPeer) AssignInterface ¶
func (p *PeerToPeer) AssignInterface(interfaceName string) error
AssignInterface - Creates TUN/TAP Interface and configures it with provided IP tool
func (*PeerToPeer) CreateMessage ¶
func (p *PeerToPeer) CreateMessage(msgType MsgType, payload []byte, proto uint16, encrypt bool) (*P2PMessage, error)
CreateMessage create internal P2P Message
func (*PeerToPeer) FindNetworkAddresses ¶
func (p *PeerToPeer) FindNetworkAddresses()
FindNetworkAddresses method lists interfaces available in the system and retrieves their IP addresses
func (*PeerToPeer) GenerateDeviceName ¶
func (p *PeerToPeer) GenerateDeviceName(i int) string
GenerateDeviceName method will generate device name if none were specified at startup
func (*PeerToPeer) HandleBadTun ¶
func (p *PeerToPeer) HandleBadTun(msg *P2PMessage, srcAddr *net.UDPAddr)
HandleBadTun notified peer about proxy being malfunction This method is not used in currenct scheme TODO: Consider to remove
func (*PeerToPeer) HandleIntroMessage ¶
func (p *PeerToPeer) HandleIntroMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
HandleIntroMessage receives an introduction string from another peer during handshake
func (*PeerToPeer) HandleIntroRequestMessage ¶
func (p *PeerToPeer) HandleIntroRequestMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
HandleIntroRequestMessage is a handshake request from another peer First 36 bytes is an ID of original sender, data after byte 36 is an endpoint on which sender was trying to communicate with this peer. We need to send this data back to him, so he knows which endpoint replied
func (*PeerToPeer) HandleNotEncryptedMessage ¶
func (p *PeerToPeer) HandleNotEncryptedMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
HandleNotEncryptedMessage is a normal message sent over p2p network
func (*PeerToPeer) HandleP2PMessage ¶
HandleP2PMessage is a handler for new messages received from P2P network
func (*PeerToPeer) HandlePingMessage ¶
func (p *PeerToPeer) HandlePingMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
HandlePingMessage is a PING message from a proxy handler
func (*PeerToPeer) HandleProxyMessage ¶
func (p *PeerToPeer) HandleProxyMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
HandleProxyMessage receives a control packet from proxy Proxy packets comes in format of UDP connection address
func (*PeerToPeer) HandleXpeerPingMessage ¶
func (p *PeerToPeer) HandleXpeerPingMessage(msg *P2PMessage, srcAddr *net.UDPAddr)
HandleXpeerPingMessage receives a cross-peer ping message
func (*PeerToPeer) IsDeviceExists ¶
func (p *PeerToPeer) IsDeviceExists(name string) bool
IsDeviceExists - checks whether interface with the given name exists in the system or not
func (*PeerToPeer) IsIPv4 ¶
func (p *PeerToPeer) IsIPv4(ip string) bool
IsIPv4 checks whether interface is IPv4 or IPv6
func (*PeerToPeer) ListenInterface ¶
func (p *PeerToPeer) ListenInterface()
ListenInterface - Listens TAP interface for incoming packets Read packets received by TAP interface and send them to a handlePacket goroutine This goroutine will execute a callback method based on packet type
func (*PeerToPeer) ParseIntroString ¶
func (p *PeerToPeer) ParseIntroString(intro string) (*PeerHandshake, error)
ParseIntroString receives a comma-separated string with ID, MAC and IP of a peer and returns this data
func (*PeerToPeer) PrepareInterfaces ¶
func (p *PeerToPeer) PrepareInterfaces(ip, interfaceName string) error
PrepareInterfaces will assign IPs to interfaces
func (*PeerToPeer) PrepareIntroductionMessage ¶
func (p *PeerToPeer) PrepareIntroductionMessage(id, endpoint string) *P2PMessage
PrepareIntroductionMessage collects client ID, mac and IP address and create a comma-separated line endpoint is an address that received this introduction message
func (*PeerToPeer) ReadDHT ¶
func (p *PeerToPeer) ReadDHT()
ReadDHT will read packets from bootstrap node
func (*PeerToPeer) SendTo ¶
func (p *PeerToPeer) SendTo(dst net.HardwareAddr, msg *P2PMessage) (int, error)
SendTo sends a p2p packet by MAC address
func (*PeerToPeer) WriteToDevice ¶
func (p *PeerToPeer) WriteToDevice(b []byte, proto uint16, truncated bool)
WriteToDevice writes data to created TAP interface
type ProxyManager ¶
type ProxyManager struct {
// contains filtered or unexported fields
}
ProxyManager manages TURN servers
func (*ProxyManager) GetList ¶
func (p *ProxyManager) GetList() []*proxyServer
GetList will return a slice of proxyServers
type RemotePeerState ¶
RemotePeerState is a state information of another peer received from DHT
type StateHandlerCallback ¶
type StateHandlerCallback func(ptpc *PeerToPeer) error
StateHandlerCallback is a peer method callback executed by peer state
type TAP ¶
type TAP interface { GetName() string GetHardwareAddress() net.HardwareAddr GetIP() net.IP GetMask() net.IPMask GetBasename() string SetName(string) SetHardwareAddress(net.HardwareAddr) SetIP(net.IP) SetMask(net.IPMask) Init(string) error Open() error Close() error Configure() error ReadPacket() (*Packet, error) WritePacket(*Packet) error Run() IsConfigured() bool MarkConfigured() }
TAP interface
type TAPLinux ¶
type TAPLinux struct { IP net.IP // IP Mask net.IPMask // Mask Mac net.HardwareAddr // Hardware Address Name string // Network interface name Tool string // Path to `ip` MTU int // MTU value Configured bool // contains filtered or unexported fields }
TAPLinux is an interface for TAP device on Linux platform
func (*TAPLinux) GetBasename ¶
GetBasename returns a prefix for automatically generated interface names
func (*TAPLinux) GetHardwareAddress ¶
func (t *TAPLinux) GetHardwareAddress() net.HardwareAddr
GetHardwareAddress returns a MAC address of the interface
func (*TAPLinux) IsConfigured ¶
func (*TAPLinux) MarkConfigured ¶
func (t *TAPLinux) MarkConfigured()
func (*TAPLinux) ReadPacket ¶
ReadPacket will read single packet from network interface
func (*TAPLinux) SetHardwareAddress ¶
func (t *TAPLinux) SetHardwareAddress(mac net.HardwareAddr)
SetHardwareAddress will set MAC
func (*TAPLinux) WritePacket ¶
WritePacket will write a single packet to interface