graph

package
v0.0.0-...-9f791b1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyExlude map[common.Address]bool

EmptyExlude 为了调用 GetBestRoutes 方便一点 EmptyExclude : to make GetBestRoutes easy to invoke.

Functions

func Channel2RouteState

func Channel2RouteState(c *channel.Channel, partenerAddress common.Address, amount *big.Int, charger fee.Charger, path []common.Address) *route.State

Channel2RouteState create a routeState from a channel

func MakeExclude

func MakeExclude(addrs ...common.Address) map[common.Address]bool

MakeExclude 为了调用 GetBestRoutes 方便一点 MakeExclude : to make GetBestRoutes easy to invoke.

Types

type ChannelGraph

type ChannelGraph struct {
	OurAddress                common.Address
	TokenAddress              common.Address
	PartenerAddress2Channel   map[common.Address]*channel.Channel
	ChannelIdentifier2Channel map[common.Hash]*channel.Channel
	// contains filtered or unexported fields
}

ChannelGraph is a Graph based on the channels and can find path between participants. 整个 ChannelGraph 只能单线程访问 The whole ChannelGraph can only be accessed by a single process.

func NewChannelGraph

func NewChannelGraph(ourAddress, tokenAddress common.Address, edges []common.Address) *ChannelGraph

NewChannelGraph create ChannelGraph,one token one channelGraph

func (*ChannelGraph) AddChannel

func (cg *ChannelGraph) AddChannel(ch *channel.Channel) error

AddChannel Instantiate a channel this node participates and add to the graph.

If the channel is already registered do nothing.

func (*ChannelGraph) AddPath

func (cg *ChannelGraph) AddPath(source, target common.Address)

AddPath Add a new edge into the network.

func (*ChannelGraph) AllNodes

func (cg *ChannelGraph) AllNodes() (nodes []common.Address)

AllNodes returns all neighbor nodes

func (*ChannelGraph) ChannelCanTransfer

func (cg *ChannelGraph) ChannelCanTransfer(partenerAddress common.Address) bool

ChannelCanTransfer returns True if the channel with `partner_address` is open and has spendable funds. """

TODO: check if the partner's network is alive

func (*ChannelGraph) GetBestRoutes

func (cg *ChannelGraph) GetBestRoutes(nodesStatus NodesStatusGetter, ourAddress common.Address,
	targetAdress common.Address, amount *big.Int, targetAmount *big.Int, excludeAddresses map[common.Address]bool, feeCharger fee.Charger) (onlineNodes []*route.State)

GetBestRoutes returns all neighbor nodes order by weight from it to target. 我们现在的路由算法应该是有历史记忆的最短路径/最小费用算法. 跳过所有已经走过的路径.

  • GetBestRoutes :function to return all neighbor nodes order by weight from it to target. *
  • Note that the routing algorithm we currently use should be the shortest-path/minimized-fee algorithm with history record,
  • which circumvents all routes that have been iterated.

func (*ChannelGraph) GetPartenerAddress2Channel

func (cg *ChannelGraph) GetPartenerAddress2Channel(address common.Address) (c *channel.Channel)

GetPartenerAddress2Channel returns a channel between me and address

func (*ChannelGraph) HasChannel

func (cg *ChannelGraph) HasChannel(source, target common.Address) bool

HasChannel return True if there is a connecting path regardless of the number of hops.

func (*ChannelGraph) RemoveChannel

func (cg *ChannelGraph) RemoveChannel(ch *channel.Channel)

RemoveChannel remove a channel from graph,and i'm a participant of this channel

func (*ChannelGraph) RemovePath

func (cg *ChannelGraph) RemovePath(source, target common.Address)

RemovePath Remove an edge from the network. this edge may not exist

func (*ChannelGraph) ShortestPath

func (cg *ChannelGraph) ShortestPath(source, target common.Address, amount *big.Int, feeCharger fee.Charger) (totalWeight int64, err error)

ShortestPath returns the shortestpath weight from source to target. make sure only be called in one thread.

type NodesStatusGetter

type NodesStatusGetter interface {
	//GetNetworkStatus return addr's status
	GetNetworkStatus(addr common.Address) (deviceType string, isOnline bool)
}

NodesStatusGetter for route service

Jump to

Keyboard shortcuts

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