server

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package server provides the Reunion protocol server.

Package server provides the Reunion protocol server.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LockedList

type LockedList struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

LockedList is used to coordinate access to it's linked list of T2 and T3 messages via the T2Message and T3Message types.

func NewLockedList

func NewLockedList() *LockedList

NewLockedList creates a new LockedList.

func (*LockedList) Append

func (l *LockedList) Append(item interface{})

Append to linked list after taking mutex.

func (*LockedList) Marshal

func (l *LockedList) Marshal() ([]byte, error)

Marshal returns a CBOR serialization of an consistent snapshot.

func (*LockedList) Range

func (l *LockedList) Range(f func(item interface{}) bool)

Range calls f sequentially for each item in the list. If f returns false, Range stops the iteration.

func (*LockedList) Serializable

func (l *LockedList) Serializable() ([]*T2T3Message, error)

Serializable returns a serializable type representing our list.

type RequestedReunionState

type RequestedReunionState struct {
	// T1Map maps T1 hashes to T1 messages.
	T1Map map[[32]byte][]byte

	// Messages is a slice of *T2T3Message.
	Messages []*T2T3Message
}

RequestedReunionState is the serialized struct type which is sent to the client in response to their fetch state command.

func (*RequestedReunionState) Marshal

func (s *RequestedReunionState) Marshal() ([]byte, error)

Marshal returns a CBOR serialization of the state.

func (*RequestedReunionState) Unmarshal

func (s *RequestedReunionState) Unmarshal(data []byte) error

Unmarshal deserializes the state CBOR blob.

type ReunionDatabase

type ReunionDatabase interface {
	// Query sends a query command to the Reunion DB and returns the
	// response command or an error.
	Query(command commands.Command) (commands.Command, error)
	CurrentSharedRandoms() ([][]byte, error)
	CurrentEpochs() ([]uint64, error)
}

ReunionDatabase is an interface which represents the Reunion DB that protocol clients interact with.

type ReunionState

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

ReunionState is the state of the Reunion DB. This is the type which is fetched by the FetchState command.

func NewReunionState

func NewReunionState() *ReunionState

NewReunionState creates a new ReunionState.

func (*ReunionState) AppendMessage

func (s *ReunionState) AppendMessage(message commands.Command) error

AppendMessage receives a message which can be one of these types: *commands.SendT1 *commands.SendT2 *commands.SendT3

func (*ReunionState) Marshal

func (s *ReunionState) Marshal() ([]byte, error)

Marshal returns a CBOR serialization of an inconsistent snapshot.

func (*ReunionState) Serializable

func (s *ReunionState) Serializable() (*SerializableReunionState, error)

Serializable returns a *SerializableReunionState copy of the data encapsulated in *ReunionState.

func (*ReunionState) SerializableT1Map

func (s *ReunionState) SerializableT1Map() (map[[32]byte][]byte, error)

SerializableT1Map returns a serializable map representing a inconsistent snapshot of our T1 sync.Map.

func (*ReunionState) Unmarshal

func (s *ReunionState) Unmarshal(data []byte) error

Unmarshal deserializes the state CBOR blob.

type ReunionStates

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

ReunionStates is a type encapsulating sync.Map of uint64 -> *ReunionState.

func NewReunionStates

func NewReunionStates() *ReunionStates

NewReunionStates creates a new ReunionStates.

func (*ReunionStates) AppendMessage

func (s *ReunionStates) AppendMessage(message commands.Command) error

AppendMessage receives a message which can be one of these types: *commands.SendT1 *commands.SendT2 *commands.SendT3

func (*ReunionStates) AtomicWriteToFile

func (s *ReunionStates) AtomicWriteToFile(filePath string) error

AtomicWriteToFile atomically writes our state to the file.

func (*ReunionStates) GarbageCollectOldEpochs

func (s *ReunionStates) GarbageCollectOldEpochs(epochClock epochtime.EpochClock)

GarbageCollectOldEpochs remove old epochs from our epochs sync.Map.

func (*ReunionStates) GetStateFromEpoch

func (s *ReunionStates) GetStateFromEpoch(epoch uint64) (*ReunionState, error)

GetStateFromEpoch returns a state given an epoch if such an entry if found in the sync.Map.

func (*ReunionStates) LoadFromFile

func (s *ReunionStates) LoadFromFile(filePath string) error

LoadFromFile loads a ReunionStates from then given file if it exists.

func (*ReunionStates) Marshal

func (s *ReunionStates) Marshal() ([]byte, error)

Marshal returns a CBOR serialization of the state.

func (*ReunionStates) MaybeAddEpochs

func (s *ReunionStates) MaybeAddEpochs(epochClock epochtime.EpochClock)

MaybeAddEpochs adds sync.Map entries for the currenlty valid epochs.

func (*ReunionStates) Unmarshal

func (s *ReunionStates) Unmarshal(data []byte) error

Marshal returns a CBOR serialization of the state.

type SerializableReunionState

type SerializableReunionState struct {
	// T1Map is a slice of the SendT1 command received from a client.
	// t1 hash -> t1
	T1Map map[[32]byte][]byte

	// MessageMap: dst t1 hash -> slice of t2/t3 messages
	MessageMap map[[32]byte][]*T2T3Message
}

SerializableReunionState represents the ReunionState in a serializable struct type.

func (*SerializableReunionState) Marshal

func (s *SerializableReunionState) Marshal() ([]byte, error)

Marshal returns a CBOR serialization of the state.

func (*SerializableReunionState) Unmarshal

func (s *SerializableReunionState) Unmarshal(data []byte) error

Unmarshal deserializes the state CBOR blob.

type SerializableReunionStates

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

SerializableReunionStates represents the serializable form of the ReunionStates type.

func (*SerializableReunionStates) Marshal

func (s *SerializableReunionStates) Marshal() ([]byte, error)

Marshal returns a CBOR serialization of the state.

func (*SerializableReunionStates) Unmarshal

func (s *SerializableReunionStates) Unmarshal(data []byte) error

Unmarshal deserializes the state CBOR blob.

type Server

type Server struct {
	sync.RWMutex
	worker.Worker
	// contains filtered or unexported fields
}

Server is a reunion server.

func NewServer

func NewServer(epochClock epochtime.EpochClock, stateFilePath, logPath, logLevel string) (*Server, error)

NewServer returns a new Server with a new ReunionState.

func NewServerFromStatefile

func NewServerFromStatefile(epochClock epochtime.EpochClock, stateFilePath, logPath, logLevel string) (*Server, error)

NewServerFromStatefile loads the state from a file.

func (*Server) GetNewLogger

func (s *Server) GetNewLogger(name string) *logging.Logger

GetNewLogger returns a logger for the given subsystem name.

func (*Server) ProcessQuery

func (s *Server) ProcessQuery(command commands.Command) (commands.Command, error)

ProcessQuery processes the given query command and returns a response command or an error.

type T1Message

type T1Message struct {
	// Payload contains the T1 message.
	Payload []byte
}

T1Message is used for serializing ReunionState.

type T2Message

type T2Message struct {
	// SrcT1Hash is the hash of the T1 message which the sender of
	// this t2 has sent.
	SrcT1Hash [sha256.Size]byte

	// Payload contains the T2 message.
	Payload []byte
}

T2Message is used for serializing ReunionState.

type T2T3Message

type T2T3Message struct {
	// SrcT1Hash is the hash of the T1 message which the sender of the
	// t2 or t3 has sent.
	SrcT1Hash [sha256.Size]byte

	// T2Payload contains the T2 message.
	T2Payload []byte

	// T3Payload contains the T3 message.
	T3Payload []byte
}

T2T3Message is used for serializing ReunionState.

type T3Message

type T3Message struct {
	// SrcT1Hash is the hash of the T1 message which the sender of
	// this t3 has sent.
	SrcT1Hash [sha256.Size]byte

	// T2Hash is the hash of the T2 message which this T3 message is replying.
	T2Hash [sha256.Size]byte

	// Payload contains the T3 message.
	Payload []byte
}

T3Message is used for serializing ReunionState.

Jump to

Keyboard shortcuts

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