transport

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HANDSHAKE_REQ   = "HANDSHAKE_REQ"
	HANDSHAKE_ACK   = "HANDSHAKE_ACK"
	HANDSHAKE_FAIL  = "HANDSHAKE_FAIL"
	PEERFIND_REQ    = "PEERFIND_REQ"
	PEERFIND_ACK    = "PEERFIND_ACK"
	PEERFIND_FAIL   = "PEERFIND_FAIL"
	PREVOTE_REQ     = "PREVOTE_REQ"
	PREVOTE_RES     = "PREVOTE_RES"
	PREVOTE_FAIL    = "PREVOTE_FAIL"
	START_JOIN_REQ  = "START_JOIN"
	START_JOIN_ACK  = "START_JOIN_ACK"
	START_JOIN_FAIL = "START_JOIN_FAIL"
	JOIN_REQ        = "JOIN_REQ"
	PUBLISH_REQ     = "PUBLISH_REQ"
	PUBLISH_ACK     = "PUBLISH_ACK"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

type Connection interface {
	SendRequest(action string, req []byte, callback func(byte []byte))
	GetSourceAddress() string
	GetDestAddress() string
	GetMessage() string
}

Interfaces

type ConnectionEntry

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

type DirectReplyChannel

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

func (*DirectReplyChannel) GetDestAddress

func (c *DirectReplyChannel) GetDestAddress() string

func (*DirectReplyChannel) GetSourceAddress

func (c *DirectReplyChannel) GetSourceAddress() string

func (*DirectReplyChannel) SendMessage

func (c *DirectReplyChannel) SendMessage(action string, b []byte) (int, error)

type HandshakeRequest

type HandshakeRequest struct {
	RemoteAddress string
}

Handshake

func HandshakeRequestFromBytes

func HandshakeRequestFromBytes(b []byte) *HandshakeRequest

func (*HandshakeRequest) ToBytes

func (h *HandshakeRequest) ToBytes() []byte

type HandshakeResponse

type HandshakeResponse struct {
	Node state.Node
}

func HandshakeResponseFromBytes

func HandshakeResponseFromBytes(b []byte) *HandshakeResponse

func (*HandshakeResponse) ToBytes

func (h *HandshakeResponse) ToBytes() []byte

type LocalConnection

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

func (*LocalConnection) GetDestAddress

func (c *LocalConnection) GetDestAddress() string

func (*LocalConnection) GetMessage

func (c *LocalConnection) GetMessage() string

func (*LocalConnection) GetSourceAddress

func (c *LocalConnection) GetSourceAddress() string

func (*LocalConnection) SendRequest

func (c *LocalConnection) SendRequest(action string, req []byte, callback func(response []byte))

type ReplyChannel

type ReplyChannel interface {
	SendMessage(action string, content []byte) (n int, err error)
	GetSourceAddress() string
	GetDestAddress() string
}

type RequestHandler

type RequestHandler func(channel ReplyChannel, req []byte)

structures

type Service

type Service struct {
	LocalNode         *state.Node
	Transport         Transport
	ConnectionManager map[string]ConnectionEntry
	ConnectionLock    sync.RWMutex
}

func NewService

func NewService(transport Transport, nodeName string) *Service

func (*Service) ConnectToRemoteNode

func (s *Service) ConnectToRemoteNode(address string, callback func(node *state.Node))

func (*Service) GetConnectedPeers

func (s *Service) GetConnectedPeers() ([]string, []state.Node)

func (*Service) GetConnection

func (s *Service) GetConnection(id string) ConnectionEntry

func (*Service) GetLocalNode

func (s *Service) GetLocalNode() state.Node

func (*Service) GetNodeByAddress

func (s *Service) GetNodeByAddress(address string) *state.Node

func (*Service) GetSeedHosts

func (s *Service) GetSeedHosts() []string

func (*Service) RegisterRequestHandler

func (s *Service) RegisterRequestHandler(action string, handler RequestHandler)

func (*Service) SendRequest

func (s *Service) SendRequest(node state.Node, action string, req []byte, callback func(response []byte))

func (*Service) SendRequestConn

func (s *Service) SendRequestConn(conn Connection, action string, req []byte, callback func(response []byte))

func (*Service) SetConnection

func (s *Service) SetConnection(key string, conn ConnectionEntry)

func (*Service) Start

func (s *Service) Start(port int)

type Transport

type Transport interface {
	OpenConnection(address string, callback func(conn Connection))
	Start(port int)
	Register(action string, handler RequestHandler)
	GetLocalAddress() string
	GetSeedHosts() []string
	GetNodeId() string
	GetHandler(action string) RequestHandler
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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