server

package
v0.0.0-...-ff0694d Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServeCmd  = iota
	SearchCmd = iota
)
View Source
const (
	DefaultHost                   = "0.0.0.0"
	DefaultPort                   = "50051"
	DefaultEsHost                 = "http://localhost"
	DefaultEsIndex                = "claims"
	DefaultEsPort                 = "9200"
	DefaultPrometheusPort         = "2112"
	DefaultRefreshDelta           = 5
	DefaultCacheTTL               = 5
	DefaultPeerFile               = "peers.txt"
	DefaultCountry                = "US"
	DefaultDisableLoadPeers       = false
	DefaultDisableStartPrometheus = false
	DefaultDisableStartUDP        = false
	DefaultDisableWritePeers      = false
	DefaultDisableFederation      = false
)
View Source
const DefaultSearchSize = 1000

DefaultSearchSize is the default max number of items an es search will return.

Variables

This section is empty.

Functions

func AddIndividualTermFields

func AddIndividualTermFields(q *elastic.BoolQuery, arr []string, name string, invert bool) *elastic.BoolQuery

AddIndividualTermFields takes a bool query, an array of string values a term name, and a bool to invert the query, and adds multiple individual TermQuerys for that name matching each of the values.

func AddInvertibleField

func AddInvertibleField(q *elastic.BoolQuery, field *pb.InvertibleField, name string) *elastic.BoolQuery

AddInvertibleField takes a bool query, an invertible field and a term name and adds a term query for that name matching that invertible field.

func AddRangeField

func AddRangeField(q *elastic.BoolQuery, rqs []*pb.RangeField, name string) *elastic.BoolQuery

AddRangeField takes a bool query, a range field struct and a term name and adds a term query for that name matching that range field.

func AddTermField

func AddTermField(q *elastic.BoolQuery, value string, name string) *elastic.BoolQuery

AddTermField takes an es bool query, a string value and a term name and adds a TermQuery for that name matching that value to the bool query.

func AddTermsField

func AddTermsField(q *elastic.BoolQuery, arr []string, name string) *elastic.BoolQuery

AddTermsField takes an es bool query, array of string values and a term name and adds a TermsQuery for that name matching those values to the bool query.

func AddTermsFieldInt32

func AddTermsFieldInt32(q *elastic.BoolQuery, arr []int32, name string) *elastic.BoolQuery

AddTermsFieldInt32 takes an es bool query, array of int32 values and a term name and adds a TermsQuery for that name matching those values to the bool query.

func EncodeAddress

func EncodeAddress(addr string) []byte

EncodeAddress takes an ipv4 address and encodes it into bytes for the hub Ping/Pong protocol.

func GetEnvironment

func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string

GetEnvironment takes the environment variables as an array of strings and a getkeyval function to turn it into a map.

func GetEnvironmentStandard

func GetEnvironmentStandard() map[string]string

GetEnvironmentStandard gets the environment variables as a map.

func Int32ArrToInterface

func Int32ArrToInterface(arr []int32) []interface{}

Int32ArrToInterface takes an array of int32 and returns them as an array of interfaces.

func RoundUpReleaseTime

func RoundUpReleaseTime(q *elastic.BoolQuery, rqs []*pb.RangeField, name string) *elastic.BoolQuery

RoundUpReleaseTime take a bool query, a range query and a term name and adds a term query for that name (this is for the release time field) with the value rounded up.

func StrArrToInterface

func StrArrToInterface(arr []string) []interface{}

StrArrToInterface takes an array of strings and returns them as an array of interfaces.

func UDPServer

func UDPServer(args *Args) error

UDPServer is a goroutine that starts an udp server that implements the hubs Ping/Pong protocol to find out about each other without making full TCP connections.

Types

type Args

type Args struct {
	CmdType                int
	Host                   string
	Port                   string
	EsHost                 string
	EsPort                 string
	PrometheusPort         string
	EsIndex                string
	RefreshDelta           int
	CacheTTL               int
	PeerFile               string
	Country                string
	DisableEs              bool
	Debug                  bool
	DisableLoadPeers       bool
	DisableStartPrometheus bool
	DisableStartUDP        bool
	DisableWritePeers      bool
	DisableFederation      bool
}

Args struct contains the arguments to the hub server.

func ParseArgs

func ParseArgs(searchRequest *pb.SearchRequest) *Args

ParseArgs parses the command line arguments when started the hub server.

type Peer

type Peer struct {
	Address  string
	Port     string
	LastSeen time.Time
}

Peer holds relevant information about peers that we know about.

type SPVPing

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

SPVPing is a struct for the format of how to ping another hub over udp. format b'!lB64s'

type SPVPong

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

SPVPong is a struct for the return pong from another hub server. format b'!BBL32s4sH'

func UDPPing

func UDPPing(ip, port string) (*SPVPong, error)

UDPPing sends a ping over udp to another hub and returns the ip address of this hub.

func (*SPVPong) DecodeAddress

func (pong *SPVPong) DecodeAddress() net.IP

DecodeAddress gets the string ipv4 address from an SPVPong struct.

func (*SPVPong) DecodeCountry

func (pong *SPVPong) DecodeCountry() string

func (*SPVPong) DecodeFlags

func (pong *SPVPong) DecodeFlags() byte

func (*SPVPong) DecodeHeight

func (pong *SPVPong) DecodeHeight() int

func (*SPVPong) DecodeProtocolVersion

func (pong *SPVPong) DecodeProtocolVersion() int

func (*SPVPong) DecodeTip

func (pong *SPVPong) DecodeTip() []byte

func (*SPVPong) Encode

func (pong *SPVPong) Encode() []byte

Encode is a function for SPVPong structs to encode them into bytes for sending over udp.

type Server

type Server struct {
	GrpcServer       *grpc.Server
	Args             *Args
	MultiSpaceRe     *regexp.Regexp
	WeirdCharsRe     *regexp.Regexp
	EsClient         *elastic.Client
	QueryCache       *ttlcache.Cache
	S256             *hash.Hash
	LastRefreshCheck time.Time
	RefreshDelta     time.Duration
	NumESRefreshes   int64
	PeerServers      map[string]*Peer
	PeerServersMut   sync.RWMutex
	NumPeerServers   *int64
	PeerSubs         map[string]*Peer
	PeerSubsMut      sync.RWMutex
	NumPeerSubs      *int64
	ExternalIP       net.IP
	pb.UnimplementedHubServer
}

func MakeHubServer

func MakeHubServer(ctx context.Context, args *Args) *Server

MakeHubServer takes the arguments given to a hub when it's started and initializes everything. It loads information about previously known peers, creates needed internal data structures, and initializes goroutines.

func (*Server) AddPeer

func (s *Server) AddPeer(ctx context.Context, args *pb.ServerMessage) (*pb.StringValue, error)

AddPeer is a grpc endpoint to tell this hub about another hub in the network.

func (*Server) Hello

func (s *Server) Hello(ctx context.Context, args *pb.HelloMessage) (*pb.HelloMessage, error)

Hello is a grpc endpoint to allow another hub to tell us about itself. The passed message includes information about the other hub, and all of its peers which are added to the knowledge of this hub.

func (*Server) PeerServersLoadOrStore

func (s *Server) PeerServersLoadOrStore(peer *Peer) (actual *Peer, loaded bool)

func (*Server) PeerSubsLoadOrStore

func (s *Server) PeerSubsLoadOrStore(peer *Peer) (actual *Peer, loaded bool)

func (*Server) PeerSubscribe

func (s *Server) PeerSubscribe(ctx context.Context, in *pb.ServerMessage) (*pb.StringValue, error)

PeerSubscribe adds a peer hub to the list of subscribers to update about new peers.

func (*Server) Ping

func (s *Server) Ping(ctx context.Context, args *pb.EmptyMessage) (*pb.StringValue, error)

Ping is a grpc endpoint that returns a short message.

func (*Server) Run

func (s *Server) Run()

func (*Server) Search

func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs, error)

Search /* Search logic is as follows: 1) Setup query with params given 2) Do query with limit of 1000 3) remove blocked content (these are returned separately) 4) remove duplicates (these are not returned) 5) limit claims per channel logic 6) get claims referenced by reposts 7) get channels references by claims and repost claims 8) return streams referenced by repost and all channel referenced in extra_txos */

func (*Server) Version

func (s *Server) Version(ctx context.Context, args *pb.EmptyMessage) (*pb.StringValue, error)

Version is a grpc endpoint to get this hub's version.

Jump to

Keyboard shortcuts

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