node

package
v0.0.17 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2015 License: BSD-3-Clause Imports: 14 Imported by: 8

Documentation

Index

Constants

View Source
const (
	//Disconnected represents mynode is disconnected.
	Disconnected = iota
	//Port0 represents mynode is behind NAT and not opened.
	Port0
	//UPnP represents mynode is opned by uPnP.
	UPnP
	//Normal represents port was opened manually.
	Normal
	//Relay represents relayed
	Relay
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

type Manager struct {
	*ManagerConfig
	// contains filtered or unexported fields
}

Manager represents the map that maps datfile to it's source node list.

func NewManager

func NewManager(cfg *ManagerConfig) *Manager

NewManager read the file and returns NodeManager obj.

func (*Manager) AppendToTable

func (lt *Manager) AppendToTable(datfile string, n *Node)

AppendToTable add node n to table if it is allowd and list doesn't have it.

func (*Manager) Get

func (lt *Manager) Get(datfile string, def Slice) Slice

Get returns rawnodelist associated with datfile if not found returns def

func (*Manager) GetNodestrSlice

func (lt *Manager) GetNodestrSlice() []string

GetNodestrSlice returns Nodestr of all nodes.

func (*Manager) GetNodestrSliceInTable

func (lt *Manager) GetNodestrSliceInTable(datfile string) []string

GetNodestrSliceInTable returns Nodestr slice of nodes associated datfile thread.

func (*Manager) Initialize

func (lt *Manager) Initialize(allnodes Slice)

Initialize pings one of initNode except myself and added it if success, and get another node info from each nodes in nodelist.

func (*Manager) Join

func (lt *Manager) Join(n *Node) bool

Join tells n to join and adds n to nodelist if welcomed. if n returns another nodes, repeats it and return true.. removes fron nodelist if not welcomed and return false.

func (*Manager) ListLen

func (lt *Manager) ListLen() int

ListLen returns size of nodelist.

func (*Manager) NodeLen

func (lt *Manager) NodeLen() int

NodeLen returns size of all nodes.

func (*Manager) NodesForGet added in v0.0.6

func (lt *Manager) NodesForGet(datfile string, searchDepth int) Slice

NodesForGet returns nodes which has datfile cache , and that extends nodes to #searchDepth .

func (*Manager) Random

func (lt *Manager) Random(exclude Slice, num int) []*Node

Random selects # of min(all # of nodes,n) nodes randomly except exclude nodes.

func (*Manager) RemoveFromAllTable

func (lt *Manager) RemoveFromAllTable(n *Node) bool

RemoveFromAllTable removes node n from all tables and return true if exists. or returns false if not exists.

func (*Manager) RemoveFromList

func (lt *Manager) RemoveFromList(n *Node) bool

RemoveFromList removes node n from nodelist and return true if exists. or returns false if not exists.

func (*Manager) RemoveFromTable

func (lt *Manager) RemoveFromTable(datfile string, n *Node) bool

RemoveFromTable removes node n and return true if exists. or returns false if not exists.

func (*Manager) ReplaceNodeInList

func (lt *Manager) ReplaceNodeInList(n *Node) *Node

ReplaceNodeInList removes one node and say bye to the node and add n in nodelist. if len(node)>defaultnode

func (*Manager) Sync

func (lt *Manager) Sync()

Sync saves k=datfile, v=Nodestr map to the file.

func (*Manager) TellUpdate

func (lt *Manager) TellUpdate(datfile string, stamp int64, id string, node *Node)

TellUpdate makes mynode info from node or dnsname or ip addr, and broadcast the updates of record id=id in cache c.datfile with stamp.

type ManagerConfig

type ManagerConfig struct {
	Lookup    string
	Fmutex    *sync.RWMutex
	NodeAllow *util.RegexpList
	NodeDeny  *util.RegexpList
	Myself    *Myself
	InitNode  *util.ConfList
}

ManagerConfig contains params for NodeManager struct.

type Myself

type Myself struct {
	Path       string
	ServerName string
	// contains filtered or unexported fields
}

Myself contains my node info.

func NewMyself

func NewMyself(internalPort int, path string, serverName string, serveHTTP http.HandlerFunc, networkMode string) *Myself

NewMyself returns Myself obj.

func (*Myself) GetStatus added in v0.0.7

func (m *Myself) GetStatus() int

GetStatus returns status.

func (*Myself) IPPortPath

func (m *Myself) IPPortPath() *Node

IPPortPath returns node ojb contains ip:port/path.

func (*Myself) InitConnection added in v0.0.13

func (m *Myself) InitConnection(nodes Slice)

InitConnection setups connection.

func (*Myself) IsRelayed added in v0.0.5

func (m *Myself) IsRelayed() bool

IsRelayed returns true is relayed.

func (*Myself) Nodestr

func (m *Myself) Nodestr() string

Nodestr returns nodestr.

func (*Myself) RelayServer added in v0.0.5

func (m *Myself) RelayServer() string

RelayServer returns nodestr of relay server.

type Node

type Node struct {
	*NodeConfig
	Nodestr string
}

Node represents node info.

func MakeNode

func MakeNode(host, path string, port int) (*Node, error)

MakeNode makes node from host info.

func MustNewNodes added in v0.0.11

func MustNewNodes(names []string) []*Node

MustNewNodes makes node slice from names.

func (*Node) Equals added in v0.0.6

func (n *Node) Equals(nn *Node) bool

Equals return true is Nodestr is equal.

func (*Node) GetherNodes added in v0.0.11

func (n *Node) GetherNodes() []*Node

GetherNodes gethers nodes from n.

func (*Node) IsAllowed

func (n *Node) IsAllowed() bool

IsAllowed returns fase if n is not allowed and denied.

func (*Node) Ping

func (n *Node) Ping() (string, error)

Ping pings to n and return response.

func (*Node) Talk

func (n *Node) Talk(message string, proxy bool, fn func(string) error) ([]string, error)

Talk talks with n with the message and returns data.

type NodeConfig

type NodeConfig struct {
	Myself    *Myself
	NodeAllow *util.RegexpList
	NodeDeny  *util.RegexpList
	Version   string
}

NodeConfig contains params for Node struct.

var NodeCfg *NodeConfig

NodeCfg is a global stuf for Node struct. it must be set before using it.

type Slice

type Slice []*Node

Slice is slice of node.

func (Slice) Has added in v0.0.6

func (ns Slice) Has(n *Node) bool

Has returns true if ns has n.

func (Slice) Len

func (ns Slice) Len() int

Len returns size of nodes.

func (Slice) Swap

func (ns Slice) Swap(i, j int)

Swap swaps nodes order.

Jump to

Keyboard shortcuts

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