2021-10-08 12:39:31 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 The NGI Pointer Secure-Scuttlebutt Team of 2020/2021
|
|
|
|
//
|
2021-02-09 11:53:33 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-02-01 15:45:30 +00:00
|
|
|
package server
|
2021-01-25 17:31:09 +00:00
|
|
|
|
|
|
|
import (
|
2022-11-07 09:18:13 +00:00
|
|
|
"github.com/ssbc/go-muxrpc/v2"
|
|
|
|
"github.com/ssbc/go-muxrpc/v2/typemux"
|
2021-05-21 07:27:12 +00:00
|
|
|
kitlog "go.mindeco.de/log"
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
"github.com/ssbc/go-ssb-room/v2/internal/network"
|
|
|
|
"github.com/ssbc/go-ssb-room/v2/roomdb"
|
|
|
|
"github.com/ssbc/go-ssb-room/v2/roomstate"
|
2021-01-25 17:31:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/* manifest:
|
|
|
|
{
|
|
|
|
"announce": "sync",
|
|
|
|
"leave": "sync",
|
|
|
|
"connect": "duplex",
|
|
|
|
"endpoints": "source",
|
|
|
|
"isRoom": "async",
|
|
|
|
"ping": "sync",
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2021-05-17 07:11:29 +00:00
|
|
|
func New(log kitlog.Logger, netInfo network.ServerEndpointDetails, m *roomstate.Manager, members roomdb.MembersService, config roomdb.RoomConfig) *Handler {
|
2021-03-11 17:40:33 +00:00
|
|
|
var h = new(Handler)
|
2021-05-17 07:11:29 +00:00
|
|
|
h.netInfo = netInfo
|
2021-02-10 14:50:36 +00:00
|
|
|
h.logger = log
|
|
|
|
h.state = m
|
2022-10-31 15:42:32 +00:00
|
|
|
h.membersdb = members
|
2021-03-24 09:58:32 +00:00
|
|
|
h.config = config
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
return h
|
|
|
|
}
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-05-17 13:31:29 +00:00
|
|
|
func (h *Handler) RegisterTunnel(mux typemux.HandlerMux) {
|
|
|
|
var namespace = muxrpc.Method{"tunnel"}
|
2021-05-17 07:11:29 +00:00
|
|
|
mux.RegisterAsync(append(namespace, "isRoom"), typemux.AsyncFunc(h.metadata))
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterAsync(append(namespace, "ping"), typemux.AsyncFunc(h.ping))
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterAsync(append(namespace, "announce"), typemux.AsyncFunc(h.announce))
|
|
|
|
mux.RegisterAsync(append(namespace, "leave"), typemux.AsyncFunc(h.leave))
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterSource(append(namespace, "endpoints"), typemux.SourceFunc(h.endpoints))
|
2021-01-25 17:31:09 +00:00
|
|
|
|
2021-04-21 09:02:25 +00:00
|
|
|
mux.RegisterDuplex(append(namespace, "connect"), connectHandler{
|
|
|
|
logger: h.logger,
|
2021-05-17 07:11:29 +00:00
|
|
|
self: h.netInfo.RoomID,
|
2021-04-21 09:02:25 +00:00
|
|
|
state: h.state,
|
|
|
|
})
|
2021-01-25 17:31:09 +00:00
|
|
|
}
|
2021-05-17 13:31:29 +00:00
|
|
|
|
|
|
|
func (h *Handler) RegisterRoom(mux typemux.HandlerMux) {
|
|
|
|
var namespace = muxrpc.Method{"room"}
|
|
|
|
mux.RegisterAsync(append(namespace, "metadata"), typemux.AsyncFunc(h.metadata))
|
|
|
|
mux.RegisterAsync(append(namespace, "ping"), typemux.AsyncFunc(h.ping))
|
|
|
|
|
2021-05-17 14:05:51 +00:00
|
|
|
mux.RegisterSource(append(namespace, "attendants"), typemux.SourceFunc(h.attendants))
|
2022-10-31 15:42:32 +00:00
|
|
|
mux.RegisterSource(append(namespace, "members"), typemux.SourceFunc(h.members))
|
2021-05-17 13:31:29 +00:00
|
|
|
|
|
|
|
mux.RegisterDuplex(append(namespace, "connect"), connectHandler{
|
|
|
|
logger: h.logger,
|
|
|
|
self: h.netInfo.RoomID,
|
|
|
|
state: h.state,
|
|
|
|
})
|
|
|
|
}
|