discovery

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DiscoveryQueryTimeout = 3 * time.Second
)
View Source
const LocalSource = "::inmemory::"

LocalSource will be treated as external source, but will be shared with other servers. The rest of the external source will not be shared to avoid infinite looping.

Variables

This section is empty.

Functions

func PublishChannel

func PublishChannel(Conn net.Conn, Channel string, AddressURLs []string) error

PublishChannel publishes current peerinfo into the connection to the server. Returns any error encountered, the connection will stay alive after the publish is done.

func Watch

func Watch(ctx context.Context, Conn net.Conn, Channel string, PrefixMatch bool, Callback func(*PeerInfo) error) error

Returns error only if ctx is cancelled, `Callback` returns error or initial handshake failed.

Types

type Config

type Config struct {
	TracerFunc        util.TracerFunc
	EvictExistingPeer bool
}

type Peer

type Peer struct {
	Conn     *trackConn
	PeerInfo *PeerInfo
}

type PeerInfo

type PeerInfo struct {
	CreatedAt time.Time `json:"create-at"`
	Channel   string    `json:"channel"`

	AddressURLs []string `json:"address-urls"`
}

func QueryChannel

func QueryChannel(Conn net.Conn, Channel string, PrefixMatch bool) ([]*PeerInfo, error)

QueryChannel queries the channel info from the connection to the server. The connection will not be closed by this function.

type Request

type Request struct {
	Type    string `json:"type"`
	Payload string `json:"payload"`

	PeerInfo []*PeerInfo `json:"peer-info"`
	// Only works for queries.
	PrefixMatch bool `json:"prefix-match"`
}

type Response

type Response struct {
	Payload string `json:"payload"`

	PeerInfo []*PeerInfo `json:"peer-info"`
	Success  bool        `json:"success"`
}

type Server

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

func New

func New(config *Config) *Server

func (*Server) AddExternalSource

func (s *Server) AddExternalSource(sourceName string, InfoMap []*PeerInfo)

func (*Server) Close

func (s *Server) Close() error

func (*Server) ListChannel

func (s *Server) ListChannel(Channel string, PrefixMatch bool) []*PeerInfo

func (*Server) Serve

func (s *Server) Serve(lis net.Listener) error

func (*Server) ServeConnection

func (s *Server) ServeConnection(c net.Conn)

ServeConnection will close the connection once done.

func (*Server) UpdateExternalStorageTable

func (s *Server) UpdateExternalStorageTable(sourceName string, info *PeerInfo)

Jump to

Keyboard shortcuts

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