common

package
v0.0.0-...-657bed6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2016 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusCreated = iota
	StatusRunned
	StatusStopping
	StatusStopped
)
View Source
const (
	STUNAddress = "stun.l.google.com:19302"
)

Variables

This section is empty.

Functions

func GetRandomPort

func GetRandomPort(args ...int) int

func RandomBytes

func RandomBytes(len int) []byte

Types

type BaseService

type BaseService struct {
	Service
	// contains filtered or unexported fields
}

func (*BaseService) IsNeedStop

func (s *BaseService) IsNeedStop() bool

func (*BaseService) SetStatus

func (s *BaseService) SetStatus(v uint32)

func (*BaseService) Status

func (s *BaseService) Status() uint32

func (*BaseService) Stop

func (s *BaseService) Stop()

type Config

type Config struct {
	SecretKey string
	NetworkID string
}

type DiscoveryDHT

type DiscoveryDHT struct {
	BaseService
	// contains filtered or unexported fields
}

func (*DiscoveryDHT) Init

func (d *DiscoveryDHT) Init(ln *LocalNode) error

func (DiscoveryDHT) Name

func (d DiscoveryDHT) Name() string

func (*DiscoveryDHT) Run

func (d *DiscoveryDHT) Run() error

func (*DiscoveryDHT) Stop

func (d *DiscoveryDHT) Stop()

type HttpService

type HttpService struct {
	BaseService
	// contains filtered or unexported fields
}

func (*HttpService) Init

func (hs *HttpService) Init(ln *LocalNode) (err error)

func (*HttpService) Name

func (hs *HttpService) Name() string

func (*HttpService) Run

func (hs *HttpService) Run() error

type InterfaceService

type InterfaceService struct {
	BaseService
	// contains filtered or unexported fields
}

func (*InterfaceService) Init

func (is *InterfaceService) Init(ln *LocalNode) (err error)

func (*InterfaceService) Name

func (is *InterfaceService) Name() string

func (*InterfaceService) Run

func (is *InterfaceService) Run() error

func (*InterfaceService) WritePacket

func (is *InterfaceService) WritePacket(packet []byte)

type ListenerService

type ListenerService struct {
	BaseService
	// contains filtered or unexported fields
}

func (*ListenerService) Init

func (l *ListenerService) Init(ln *LocalNode) error

func (ListenerService) Name

func (l ListenerService) Name() string

func (*ListenerService) Run

func (l *ListenerService) Run() error

func (*ListenerService) Stop

func (l *ListenerService) Stop()

type LocalNode

type LocalNode struct {
	Node
	// contains filtered or unexported fields
}

func NewLocalNode

func NewLocalNode(cfg *Config) (*LocalNode, error)

func (*LocalNode) AddService

func (n *LocalNode) AddService(srv Service)

func (*LocalNode) Config

func (n *LocalNode) Config() Config

func (*LocalNode) NetTable

func (n *LocalNode) NetTable() *NetTable

func (*LocalNode) NetworkSecret

func (n *LocalNode) NetworkSecret() *secure.NetworkSecret

func (*LocalNode) Service

func (n *LocalNode) Service(name string) Service

func (*LocalNode) Start

func (n *LocalNode) Start() error

func (*LocalNode) State

func (n *LocalNode) State() State

func (*LocalNode) Stop

func (n *LocalNode) Stop() error

func (*LocalNode) WaitStop

func (n *LocalNode) WaitStop()

type NetTable

type NetTable struct {
	BaseService
	// contains filtered or unexported fields
}

func (*NetTable) AddRemoteNode

func (nt *NetTable) AddRemoteNode(rn *RemoteNode)

func (*NetTable) GetDHTInChannel

func (nt *NetTable) GetDHTInChannel() chan<- string

func (*NetTable) Init

func (nt *NetTable) Init(ln *LocalNode) error

func (NetTable) Name

func (nt NetTable) Name() string

func (*NetTable) PeerAddresses

func (nt *NetTable) PeerAddresses() map[string]string

func (*NetTable) RemoteNodeByIP

func (nt *NetTable) RemoteNodeByIP(ip net.IP) *RemoteNode

func (*NetTable) RemoveRemoteNode

func (nt *NetTable) RemoveRemoteNode(ip net.IP)

func (*NetTable) Run

func (nt *NetTable) Run() error

func (*NetTable) SendPacket

func (nt *NetTable) SendPacket(dstIP net.IP, payload []byte)

func (*NetTable) Stop

func (nt *NetTable) Stop()

type Node

type Node struct {
	ID         string
	PublicKey  []byte
	Host       string
	Port       int
	InternalIP string
	LastSeen   uint64
}

type NodeSet

type NodeSet struct {
	// contains filtered or unexported fields
}

func NewNodeSet

func NewNodeSet() *NodeSet

func (*NodeSet) Add

func (s *NodeSet) Add(key string, value interface{})

func (*NodeSet) Data

func (s *NodeSet) Data() map[string]NodeSetElement

func (*NodeSet) Merge

func (s *NodeSet) Merge(values map[string]NodeSetElement)

func (*NodeSet) Remove

func (s *NodeSet) Remove(key string)

func (*NodeSet) Select

func (s *NodeSet) Select(key string) interface{}

func (*NodeSet) String

func (s *NodeSet) String() string

type NodeSetElement

type NodeSetElement struct {
	Add, Remove time.Time
	Value       interface{}
}

func (NodeSetElement) String

func (ne NodeSetElement) String() string

type RemoteNode

type RemoteNode struct {
	Node
	// contains filtered or unexported fields
}

func NewRemoteNode

func NewRemoteNode(conn net.Conn, sessionKey []byte, privateIP net.IP) *RemoteNode

func TryConnect

func TryConnect(h string, networkSecret *secure.NetworkSecret, ln *LocalNode) (*RemoteNode, error)

func (*RemoteNode) Close

func (rn *RemoteNode) Close()

func (*RemoteNode) SendPack

func (rn *RemoteNode) SendPack(pack *protocol.Packet) (err error)

func (*RemoteNode) SendToInterface

func (rn *RemoteNode) SendToInterface(payload []byte) error

type Response

type Response struct {
	IfaceName   string      `json:"iface"`
	LocalIPAddr string      `json:"local_ip_addr"`
	Peers       interface{} `json:"net_peers"`
}

type STUNService

type STUNService struct {
	BaseService
	// contains filtered or unexported fields
}

func (*STUNService) Init

func (s *STUNService) Init(ln *LocalNode) error

func (STUNService) Name

func (d STUNService) Name() string

func (*STUNService) Run

func (s *STUNService) Run() error

type Service

type Service interface {
	Init(*LocalNode) error
	Name() string
	Run() error
	Stop()
}

type State

type State struct {
	Secret     *secure.NetworkSecret `json:"-"`
	ListenPort int                   `json:"port"`
	PrivateIP  net.IP                `json:"private_ip"`
	// contains filtered or unexported fields
}

func NewState

func NewState(secret *secure.NetworkSecret) *State

func (*State) Load

func (s *State) Load()

func (*State) Save

func (s *State) Save()

type UPnPService

type UPnPService struct {
	BaseService
	// contains filtered or unexported fields
}

func (*UPnPService) Init

func (s *UPnPService) Init(ln *LocalNode) error

func (UPnPService) Name

func (d UPnPService) Name() string

func (*UPnPService) Run

func (s *UPnPService) Run() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL