v1

package
v0.0.0-...-bfa3324 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: CC0-1.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Msg

type Msg struct {
	Id   uint32   `json:"id"`
	Hops []uint32 `json:"hops"`
}

type Peer

type Peer struct {
	Id          uint32
	Addr        string
	Target      map[uint32]string
	Peers       map[net.Conn]*PeerInfo
	Lock        *sync.RWMutex
	Queue       []*Msg
	QueueLock   *sync.RWMutex
	Log         bool
	Logger      *os.File
	PingClient  chan struct{}
	Traffic     map[uint32]*TrafficCost
	TrafficLock *sync.Mutex
}

func New

func New(ctx context.Context, id uint32, addr string, target map[uint32]string, keepLog bool) (*Peer, error)

func (*Peer) Add

func (p *Peer) Add(conn net.Conn, id uint32, notifier chan Msg) bool

Invoked when peer has established connection with another peer

func (*Peer) Client

func (p *Peer) Client(ctx context.Context, done chan struct{})

func (*Peer) Enqueue

func (p *Peer) Enqueue(msg *Msg)

Enqueues newly received message, also appends to logs file when necessary

func (*Peer) ExportTrafficCost

func (p *Peer) ExportTrafficCost() error

func (*Peer) Forward

func (p *Peer) Forward(msg *Msg)

See if this message need to be forwarded to any another peers

func (*Peer) LogHandler

func (p *Peer) LogHandler(ctx context.Context)

Run a go-routine, used for listening to context cancellation signal and on reception closes log file handler --- part of graceful shutdown

func (*Peer) Remove

func (p *Peer) Remove(conn net.Conn)

Invoked by connection handler method when connection is about to be terminated for removing peer from this peer's connected set

func (*Peer) Server

func (p *Peer) Server(ctx context.Context, done chan struct{})

func (*Peer) UpdateTrafficCost

func (p *Peer) UpdateTrafficCost(id uint32, isInwards bool, size uint64)

type PeerInfo

type PeerInfo struct {
	Id   uint32
	Addr string
	Ping chan Msg
}

type TrafficCost

type TrafficCost struct {
	In  uint64
	Out uint64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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