...

Package peer

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

Overview ▾

Constants

const (
    MaxSyncDuration           time.Duration = time.Hour * 24 * 30 // a month
    MaxSyncNumberOfMessages   int           = 1000
    MaxSyncNumberOfOperations int           = 1000
)
const (
    IdleTimeout time.Duration = 1 * time.Second
)
const (
    /* Limits the number of entities in the state buffer.
    The deepest possible path is the following:
        RootMessage by UnknownUser(0)
         L Reply(1) by UnknownUser(1)
           L Reply(2) by UnknwonUser(2)
             L ...
               L Reply(MaxMessageDepth) by UnknownUser(MaxMessageDepth)
                 L Operation on Reply(MaxMessageDepth) by UnknownUser(MaxMessageDepth+1)
    The total number of entities in the path is:
        Operations; 1 entity
        Messages:   MaxMessageDepth+1 entities   // RootMessage + Reply*MaxMessageDepth
        Users:      MaxMessageDepth+2 entities   // UnknownUser*(MaxMessageDepth + 2)
    */
    MaxPendingEntitiesNum int = (entity.MaxMessageDepth + 2) * 2
)
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
    State           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 StateActiveSyncing

StateActiveSyncing implements the active part of the sync protocol. In case of success, switches peer to either Idle (for peers connected via passive connections) or StatePassiveSyncing (for peers connected via active connections).

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

func (*StateActiveSyncing) ID

func (s *StateActiveSyncing) ID() StateID

func (*StateActiveSyncing) Name

func (s *StateActiveSyncing) Name() string

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
    StateIDActiveSyncing
    StateIDPassiveSyncing
)

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 StatePassiveSyncing

StatePassiveSyncing implements the passive part of the sync protocol. In case of success, switches peer to either Idle (for peers connected via active connections) or StateActiveSyncing (for peers connected via passive connections).

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

func (*StatePassiveSyncing) ID

func (s *StatePassiveSyncing) ID() StateID

func (*StatePassiveSyncing) Name

func (s *StatePassiveSyncing) 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
}