peer

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2021 License: GPL-3.0 Imports: 9 Imported by: 0

README

peer

GoDoc GoReport Travis License Chat Mentioned in Awesome Go

Package peer provides ...

Overview

This package ...

Documentation

Index

Constants

View Source
const (
	// MaxMsgCountPerWave is the max number of msg per wave
	MaxMsgCountPerWave = 2
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Peer

type Peer struct {
	IP       string      `json:"ip"`
	Port     uint64      `json:"port"`
	NodeKey  string      `json:"nodeKey"`
	UserID   common.Hash `json:"userID"`
	Verified bool        `json:"verified"`
	Conn     *websocket.Conn
}

Peer contain the info of websocket connection

func New

func New(ip string, port uint64, nodeKey string) (*Peer, error)

New create new Peer

func (Peer) Address

func (p Peer) Address() string

Address is UserID@IP:port/nodeKey

func (*Peer) Close

func (p *Peer) Close() error

Close the ws connection,

func (*Peer) Connected

func (p *Peer) Connected() bool

Connected return true if this peer is connected right now

func (*Peer) Dial

func (p *Peer) Dial() error

Dial build ws connection

func (*Peer) ID

func (p *Peer) ID() common.Hash

ID return key of peer

func (*Peer) SendErr

func (p *Peer) SendErr(waveID common.Hash, err error) error

SendErr is send the error of request back

func (*Peer) SendMsg

func (p *Peer) SendMsg(waveID common.Hash, msg *core.Message) error

SendMsg is used to send msg to peer

func (*Peer) SendMsgs

func (p *Peer) SendMsgs(waveID common.Hash, msgs []*core.Message) error

SendMsgs is used to send mulitiple msgs

func (*Peer) SendPeers

func (p *Peer) SendPeers(waveID common.Hash, pm map[common.Hash]*Peer, localPeer *Peer) error

SendPeers is used to send peers of local node

func (*Peer) SendPing

func (p *Peer) SendPing(waveID common.Hash) error

SendPing is used for ping pong, send ping to peer

func (*Peer) SendPong

func (p *Peer) SendPong(waveID common.Hash) error

SendPong is used for ping pong, send pong back to peer

func (*Peer) SendQuestion

func (p *Peer) SendQuestion(waveID common.Hash, cmd string, args ...interface{}) error

SendQuestion is used to send question to peer

func (*Peer) SendRoots

func (p *Peer) SendRoots(waveID common.Hash, user0, user1 *core.User) error

SendRoots is used to send 2 roots to peer

func (*Peer) SetUserID

func (p *Peer) SetUserID(userID common.Hash)

SetUserID set author of this peer

func (*Peer) SetVerified

func (p *Peer) SetVerified()

SetVerified set verified is true

func (Peer) Url

func (p Peer) Url() string

Url show the Peer ws url address

Source Files

Jump to

Keyboard shortcuts

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