lib

package
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: GPL-3.0 Imports: 29 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.NewGaugeVec(prometheus.GaugeOpts{
		Name: "nirn_proxy_open_connections",
		Help: "Gauge for client connections currently open with the proxy",
	}, []string{"method", "route"})

	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, disableHttp2 bool, globalOverrides string, disableRestDetection bool)

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 EnvGetBool added in v1.2.1

func EnvGetBool(name string, defaultVal bool) bool

func EnvGetInt

func EnvGetInt(name string, defaultVal int) int

func EnvMustGet

func EnvMustGet(name string) string

func Generate429 added in v1.2.2

func Generate429(resp *http.ResponseWriter)

func GetBotGlobalLimit

func GetBotGlobalLimit(token string, user *BotUserResponse) (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 GlobalHook added in v1.2.1

type GlobalHook struct {
}

func (*GlobalHook) Fire added in v1.2.1

func (h *GlobalHook) Fire(e *logrus.Entry) error

func (*GlobalHook) Levels added in v1.2.1

func (h *GlobalHook) Levels() []logrus.Level

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, maxBearerLruSize 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) GetEventDelegate added in v1.1.0

func (m *QueueManager) GetEventDelegate() *NirnEvents

func (*QueueManager) GetRequestRoutingInfo added in v1.2.0

func (m *QueueManager) GetRequestRoutingInfo(req *http.Request, token string) (routingHash uint64, path string, queueType QueueType)

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 QueueType added in v1.2.0

type QueueType int64
const (
	Bot QueueType = iota
	NoAuth
	Bearer
)

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) error

Jump to

Keyboard shortcuts

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