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 entity.ID
var ZeroID ID
func (i *ID) String() string
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 }
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( conn *connection.Connection, owner *owner.Owner, validator Validator, goneChan chan *Peer, ) *Peer
func (p *Peer) AddAddresses(new []string)
func (p *Peer) Addresses() []string
func (p *Peer) ClearAddresses()
func (p *Peer) Close()
func (p *Peer) ID() *ID
func (p *Peer) Info() *Info
func (p *Peer) ShortID() string
func (p *Peer) String() string
State isolates peer from implementation of particular state protocol.
type State interface { ID() StateID Name() string // contains filtered or unexported methods }
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 (s *StateActiveSyncing) ID() StateID
func (s *StateActiveSyncing) Name() string
StateHandshaking implements the handshaking protocol.
type StateHandshaking struct {
// contains filtered or unexported fields
}
func (s *StateHandshaking) ID() StateID
func (s *StateHandshaking) Name() string
type StateID int
const ( StateIDHandshaking StateID = iota StateIDIdle StateIDSending StateIDReceiving StateIDActiveSyncing StateIDPassiveSyncing )
StateIdle implements the idle protocol (when peer is waiting for new entities from either side).
type StateIdle struct {
// contains filtered or unexported fields
}
func (s *StateIdle) ID() StateID
func (s *StateIdle) Name() string
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 (s *StatePassiveSyncing) ID() StateID
func (s *StatePassiveSyncing) Name() string
StateReceiving implements the entity receiving protocol.
type StateReceiving struct {
// contains filtered or unexported fields
}
func (s *StateReceiving) ID() StateID
func (s *StateReceiving) Name() string
StateSending implements the entity sending protocol.
type StateSending struct {
// contains filtered or unexported fields
}
func (s *StateSending) ID() StateID
func (s *StateSending) Name() string
type Validator interface { ValidatePeer(*Peer) bool }