go-ssb-room/roomsrv/init_handlers.go

71 lines
2.0 KiB
Go
Raw Normal View History

2021-03-12 13:11:10 +00:00
// SPDX-License-Identifier: MIT
package roomsrv
import (
kitlog "github.com/go-kit/kit/log"
muxrpc "go.cryptoscope.co/muxrpc/v2"
"go.cryptoscope.co/muxrpc/v2/typemux"
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/alias"
2021-03-25 08:21:19 +00:00
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/gossip"
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/signinwithssb"
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/tunnel/server"
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/whoami"
)
2021-03-16 08:10:44 +00:00
// instantiate and register the muxrpc handlers
func (s *Server) initHandlers() {
// inistaniate handler packages
whoami := whoami.New(s.Whoami())
tunnelHandler := server.New(
kitlog.With(s.logger, "unit", "tunnel"),
s.Whoami(),
s.StateManager,
s.Members,
s.Config,
)
aliasHandler := alias.New(
kitlog.With(s.logger, "unit", "aliases"),
s.Whoami(),
s.Aliases,
s.netInfo,
)
siwssbHandler := signinwithssb.New(
kitlog.With(s.logger, "unit", "auth-with-ssb"),
2021-03-24 10:39:08 +00:00
s.Whoami(),
s.netInfo.Domain,
s.Members,
s.authWithSSB,
s.authWithSSBBridge,
)
// 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)
// register tunnel.connect etc twice (as tunnel.* and room.*)
var method = muxrpc.Method{"tunnel"}
tunnelHandler.Register(mux, method)
method = muxrpc.Method{"room"}
tunnelHandler.Register(mux, method)
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))
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))
}
}