...

Package peer

import "vminko.org/dscuss/p2p/peer"
Overview
Index

Overview ▾

Constants

const (
    // Encapsulates a user entity.
    MaxPendingEntitiesNum int = 100
)
const (
    ProtocolVersion int = 1
)

type ID

type ID entity.ID
var ZeroID ID

func (*ID) String

func (i *ID) String() string

type Info

Info is a static Peer description for UI.

type Info struct {
    ShortID         string
    ID              string
    LocalAddr       string
    RemoteAddr      string
    AssociatedAddrs []string
    Nickname        string
    StateName       string
    Subscriptions   []string
}

type Peer

Peer is responsible for communication with other nodes. Implements the Dscuss protocol.

type Peer struct {
    State State
    User  *entity.User
    Subs  subs.Subscriptions
    // contains filtered or unexported fields
}

func New

func New(
    conn *connection.Connection,
    owner *owner.Owner,
    validator Validator,
    goneChan chan *Peer,
) *Peer

func (*Peer) AddAddresses

func (p *Peer) AddAddresses(new []string)

func (*Peer) Addresses

func (p *Peer) Addresses() []string

func (*Peer) ClearAddresses

func (p *Peer) ClearAddresses()

func (*Peer) Close

func (p *Peer) Close()

func (*Peer) ID

func (p *Peer) ID() *ID

func (*Peer) Info

func (p *Peer) Info() *Info

func (*Peer) ShortID

func (p *Peer) ShortID() string

func (*Peer) String

func (p *Peer) String() string

type State

State isolates peer from implementation of particular state protocol.

type State interface {
    ID() StateID
    Name() string
    // contains filtered or unexported methods
}

type StateHandshaking

StateHandshaking implements the handshaking protocol.

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

func (*StateHandshaking) ID

func (s *StateHandshaking) ID() StateID

func (*StateHandshaking) Name

func (s *StateHandshaking) Name() string

type StateID

type StateID int
const (
    StateIDHandshaking StateID = iota
    StateIDIdle
    StateIDSending
    StateIDReceiving
)

type StateIdle

StateIdle implements the idle protocol (when peer is waiting for new entities from either side).

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

func (*StateIdle) ID

func (s *StateIdle) ID() StateID

func (*StateIdle) Name

func (s *StateIdle) Name() string

type StateReceiving

StateReceiving implements the entity receiving protocol.

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

func (*StateReceiving) ID

func (s *StateReceiving) ID() StateID

func (*StateReceiving) Name

func (s *StateReceiving) Name() string

type StateSending

StateSending implements the entity sending protocol.

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

func (*StateSending) ID

func (s *StateSending) ID() StateID

func (*StateSending) Name

func (s *StateSending) Name() string

type Validator

type Validator interface {
    ValidatePeer(*Peer) bool
}