lib

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2022 License: GPL-3.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MajorUnknown      = "unk"
	MajorChannels     = "channels"
	MajorGuilds       = "guilds"
	MajorWebhooks     = "webhooks"
	MajorInvites      = "invites"
	MajorInteractions = "interactions"
)
View Source
const EpochDiscord = 1420070400000

Variables

View Source
var (
	ErrorCounter = promauto.NewCounter(prometheus.CounterOpts{
		Name: "nirn_proxy_error",
		Help: "The total number of errors when processing requests",
	})

	RequestHistogram = prometheus.NewHistogramVec(prometheus.HistogramOpts{
		Name:    "nirn_proxy_requests",
		Help:    "Request histogram",
		Buckets: []float64{.1, .25, 1, 2.5, 5, 20},
	}, []string{"method", "status", "route", "clientId"})

	ConnectionsOpen = promauto.NewGauge(prometheus.GaugeOpts{
		Name: "nirn_proxy_open_connections",
		Help: "Gauge for client connections currently open with the proxy",
	})

	RequestsRoutedSent = promauto.NewCounter(prometheus.CounterOpts{
		Name: "nirn_proxy_requests_routed_sent",
		Help: "Counter for requests routed from this node into other nodes",
	})

	RequestsRoutedRecv = promauto.NewCounter(prometheus.CounterOpts{
		Name: "nirn_proxy_requests_routed_received",
		Help: "Counter for requests received from other nodes",
	})

	RequestsRoutedError = promauto.NewCounter(prometheus.CounterOpts{
		Name: "nirn_proxy_requests_routed_error",
		Help: "Counter for failed requests routed from this node",
	})
)

Functions

func ConfigureDiscordHTTPClient

func ConfigureDiscordHTTPClient(ip string, timeout time.Duration)

func CopyResponseToResponseWriter added in v1.1.0

func CopyResponseToResponseWriter(resp *http.Response, respWriter *http.ResponseWriter) error

func EnvGet

func EnvGet(name string, defaultVal string) string

func EnvGetInt

func EnvGetInt(name string, defaultVal int) int

func EnvMustGet

func EnvMustGet(name string) string

func GetBotGlobalLimit

func GetBotGlobalLimit(token string) (uint, error)

func GetBotId

func GetBotId(token string) string

func GetMetricsPath

func GetMetricsPath(route string) string

func GetOptimisticBucketPath

func GetOptimisticBucketPath(url string, method string) string

func GetSnowflakeCreatedAt

func GetSnowflakeCreatedAt(snowflake string) (time.Time, error)

func HashCRC64

func HashCRC64(data string) uint64

func InitMemberList added in v1.1.0

func InitMemberList(knownMembers []string, port int, proxyPort string, manager *QueueManager) *memberlist.Memberlist

func IsNumericInput

func IsNumericInput(str string) bool

func IsSnowflake

func IsSnowflake(str string) bool

func ProcessRequest

func ProcessRequest(ctx context.Context, item *QueueItem) (*http.Response, error)

func SetLogger

func SetLogger(l *logrus.Logger)

func StartMetrics

func StartMetrics(addr string)

func StartProfileServer

func StartProfileServer()

Types

type BotGatewayResponse

type BotGatewayResponse struct {
	SessionStartLimit map[string]int `json:"session_start_limit"`
}

type BotUserResponse

type BotUserResponse struct {
	Id       string `json:"id"`
	Username string `json:"username"`
	Discrim  string `json:"discriminator"`
}

func GetBotUser

func GetBotUser(token string) (*BotUserResponse, error)

type ClusterGlobalRateLimiter added in v1.1.0

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

func NewClusterGlobalRateLimiter added in v1.1.0

func NewClusterGlobalRateLimiter() *ClusterGlobalRateLimiter

func (*ClusterGlobalRateLimiter) FireGlobalRequest added in v1.1.0

func (c *ClusterGlobalRateLimiter) FireGlobalRequest(ctx context.Context, addr string, botHash uint64, botLimit uint) error

func (*ClusterGlobalRateLimiter) Take added in v1.1.0

func (c *ClusterGlobalRateLimiter) Take(botHash uint64, botLimit uint)

type NirnDelegate added in v1.1.0

type NirnDelegate struct {
	memberlist.Delegate
	// contains filtered or unexported fields
}

func (NirnDelegate) GetBroadcasts added in v1.1.0

func (d NirnDelegate) GetBroadcasts(overhead int, limit int) [][]byte

func (NirnDelegate) LocalState added in v1.1.0

func (d NirnDelegate) LocalState(join bool) []byte

func (NirnDelegate) MergeRemoteState added in v1.1.0

func (d NirnDelegate) MergeRemoteState(buf []byte, join bool)

func (NirnDelegate) NodeMeta added in v1.1.0

func (d NirnDelegate) NodeMeta(limit int) []byte

func (NirnDelegate) NotifyMsg added in v1.1.0

func (d NirnDelegate) NotifyMsg(msg []byte)

type NirnEvents added in v1.1.0

type NirnEvents struct {
	memberlist.EventDelegate
	OnJoin  func(node *memberlist.Node)
	OnLeave func(node *memberlist.Node)
}

func (NirnEvents) NotifyJoin added in v1.1.0

func (d NirnEvents) NotifyJoin(node *memberlist.Node)

func (NirnEvents) NotifyLeave added in v1.1.0

func (d NirnEvents) NotifyLeave(node *memberlist.Node)

func (NirnEvents) NotifyUpdate added in v1.1.0

func (d NirnEvents) NotifyUpdate(node *memberlist.Node)

type QueueChannel

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

type QueueItem

type QueueItem struct {
	Req *http.Request
	Res *http.ResponseWriter
	// contains filtered or unexported fields
}

type QueueManager added in v1.1.0

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

func NewQueueManager added in v1.1.0

func NewQueueManager(bufferSize int) *QueueManager

func (*QueueManager) CreateMux added in v1.1.0

func (m *QueueManager) CreateMux() *http.ServeMux

func (*QueueManager) DiscordRequestHandler added in v1.1.0

func (m *QueueManager) DiscordRequestHandler(resp http.ResponseWriter, req *http.Request)

func (*QueueManager) Generate429 added in v1.1.0

func (m *QueueManager) Generate429(resp *http.ResponseWriter)

func (*QueueManager) GetEventDelegate added in v1.1.0

func (m *QueueManager) GetEventDelegate() *NirnEvents

func (*QueueManager) HandleGlobal added in v1.1.0

func (m *QueueManager) HandleGlobal(w http.ResponseWriter, r *http.Request)

func (*QueueManager) SetCluster added in v1.1.0

func (m *QueueManager) SetCluster(cluster *memberlist.Memberlist, proxyPort string)

func (*QueueManager) Shutdown added in v1.1.0

func (m *QueueManager) Shutdown()

type RequestQueue

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

func NewRequestQueue

func NewRequestQueue(processor func(ctx context.Context, item *QueueItem) (*http.Response, error), token string, bufferSize int) (*RequestQueue, error)

func (*RequestQueue) Queue

func (q *RequestQueue) Queue(req *http.Request, res *http.ResponseWriter, path string, pathHash uint64) (string, *http.Response, error)

Jump to

Keyboard shortcuts

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