Gateway working, beta

This commit is contained in:
2025-12-07 17:11:37 +01:00
parent de03c1fe3d
commit 3d6774586e
13 changed files with 616 additions and 506 deletions

View File

@@ -2,9 +2,8 @@ package ws
import (
"encoding/json"
"homestead/homestead_gateway/util/cache"
"homestead/homestead_gateway/util/queue"
"log/slog"
"sync"
"time"
"github.com/gorilla/websocket"
@@ -17,16 +16,46 @@ type WebsocketGateway struct {
upgrader websocket.Upgrader
cache *cache.Cache
queue *queue.Queue[GatewayMessageOut]
bot *websocket.Conn
conns *cache.ConnectionCache
registry *Registry
logger *slog.Logger
closeFn func() error
}
//
type Registry struct {
mu sync.RWMutex
entries map[string]*ChannelEntry
queueCap int
botMu sync.Mutex
bot *ConnWrapper
}
type ConnWrapper struct {
Conn *websocket.Conn
ServerID string // set for mods (the server_id)
LastSeen time.Time
}
type BoundedQueue struct {
mu sync.Mutex
buf []GatewayMessageOut
start int
length int
capacity int
}
type ChannelEntry struct {
mu sync.Mutex
Channel string
Mod *ConnWrapper
Queue *BoundedQueue
}
//
type User struct {
ID string `json:"id"`
Name string `json:"name"`
@@ -64,15 +93,18 @@ type GatewayAck struct {
Type string `json:"type"`
}
//
type Handshake struct {
Type string `json:"type"` // "mod" or "bot"
Data json.RawMessage `json:"data"`
}
type ModHandshake struct {
ServerID string `json:"server_id"`
ServerID string `json:"server_id"`
ChannelID string `json:"channel_id"`
}
type BotHandshake struct {
BotID string `json:"bot_id"`
ChannelId string `json:"channel_id"`
}