2021-10-08 12:39:31 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 The NGI Pointer Secure-Scuttlebutt Team of 2020/2021
|
|
|
|
//
|
2021-03-12 13:11:10 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
package roomsrv
|
|
|
|
|
|
|
|
import (
|
2022-11-07 09:18:13 +00:00
|
|
|
muxrpc "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-03-11 17:40:33 +00:00
|
|
|
|
2022-11-07 09:18:13 +00:00
|
|
|
"github.com/ssbc/go-ssb-room/v2/muxrpc/handlers/alias"
|
|
|
|
"github.com/ssbc/go-ssb-room/v2/muxrpc/handlers/gossip"
|
|
|
|
"github.com/ssbc/go-ssb-room/v2/muxrpc/handlers/signinwithssb"
|
|
|
|
"github.com/ssbc/go-ssb-room/v2/muxrpc/handlers/tunnel/server"
|
|
|
|
"github.com/ssbc/go-ssb-room/v2/muxrpc/handlers/whoami"
|
2021-03-11 17:40:33 +00:00
|
|
|
)
|
|
|
|
|
2021-03-16 08:10:44 +00:00
|
|
|
// instantiate and register the muxrpc handlers
|
2021-03-24 15:52:58 +00:00
|
|
|
func (s *Server) initHandlers() {
|
2021-03-11 17:40:33 +00:00
|
|
|
// inistaniate handler packages
|
|
|
|
whoami := whoami.New(s.Whoami())
|
|
|
|
|
|
|
|
tunnelHandler := server.New(
|
|
|
|
kitlog.With(s.logger, "unit", "tunnel"),
|
2021-05-17 07:11:29 +00:00
|
|
|
s.netInfo,
|
2021-03-11 17:40:33 +00:00
|
|
|
s.StateManager,
|
2021-03-24 09:58:32 +00:00
|
|
|
s.Members,
|
|
|
|
s.Config,
|
2021-03-11 17:40:33 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
aliasHandler := alias.New(
|
|
|
|
kitlog.With(s.logger, "unit", "aliases"),
|
|
|
|
s.Whoami(),
|
2021-03-24 15:52:58 +00:00
|
|
|
s.Aliases,
|
2021-04-19 12:52:12 +00:00
|
|
|
s.netInfo,
|
2021-03-11 17:40:33 +00:00
|
|
|
)
|
|
|
|
|
2021-03-17 09:46:05 +00:00
|
|
|
siwssbHandler := signinwithssb.New(
|
|
|
|
kitlog.With(s.logger, "unit", "auth-with-ssb"),
|
2021-03-24 10:39:08 +00:00
|
|
|
s.Whoami(),
|
2021-04-19 12:52:12 +00:00
|
|
|
s.netInfo.Domain,
|
2021-03-24 15:52:58 +00:00
|
|
|
s.Members,
|
|
|
|
s.authWithSSB,
|
|
|
|
s.authWithSSBBridge,
|
2021-03-17 09:46:05 +00:00
|
|
|
)
|
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
// register muxrpc commands
|
|
|
|
registries := []typemux.HandlerMux{s.public, s.master}
|
|
|
|
|
|
|
|
for _, mux := range registries {
|
|
|
|
mux.RegisterAsync(muxrpc.Method{"manifest"}, manifest)
|
|
|
|
mux.RegisterAsync(muxrpc.Method{"whoami"}, whoami)
|
|
|
|
|
2021-05-17 13:31:29 +00:00
|
|
|
// register old room v1 commands
|
|
|
|
tunnelHandler.RegisterTunnel(mux)
|
2021-03-11 17:40:33 +00:00
|
|
|
|
2021-05-17 13:31:29 +00:00
|
|
|
// register new room v2 commands
|
|
|
|
tunnelHandler.RegisterRoom(mux)
|
2021-03-11 17:40:33 +00:00
|
|
|
|
2021-05-17 13:31:29 +00:00
|
|
|
var method = muxrpc.Method{"room"}
|
2021-03-11 17:40:33 +00:00
|
|
|
mux.RegisterAsync(append(method, "registerAlias"), typemux.AsyncFunc(aliasHandler.Register))
|
2021-03-16 08:13:27 +00:00
|
|
|
mux.RegisterAsync(append(method, "revokeAlias"), typemux.AsyncFunc(aliasHandler.Revoke))
|
2022-08-19 19:47:33 +00:00
|
|
|
mux.RegisterAsync(append(method, "listAliases"), typemux.AsyncFunc(aliasHandler.List))
|
2021-03-17 09:46:05 +00:00
|
|
|
|
|
|
|
method = muxrpc.Method{"httpAuth"}
|
|
|
|
mux.RegisterAsync(append(method, "invalidateAllSolutions"), typemux.AsyncFunc(siwssbHandler.InvalidateAllSolutions))
|
|
|
|
mux.RegisterAsync(append(method, "sendSolution"), typemux.AsyncFunc(siwssbHandler.SendSolution))
|
|
|
|
|
2021-03-25 08:21:19 +00:00
|
|
|
method = muxrpc.Method{"gossip"}
|
|
|
|
mux.RegisterDuplex(append(method, "ping"), typemux.DuplexFunc(gossip.Ping))
|
2021-03-11 17:40:33 +00:00
|
|
|
}
|
|
|
|
}
|