2021-03-12 13:11:10 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-11 17:40:33 +00:00
|
|
|
package roomsrv
|
|
|
|
|
|
|
|
import (
|
|
|
|
kitlog "github.com/go-kit/kit/log"
|
2021-03-17 09:46:05 +00:00
|
|
|
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/signinwithssb"
|
2021-03-11 17:40:33 +00:00
|
|
|
"github.com/ssb-ngi-pointer/go-ssb-room/roomdb"
|
|
|
|
muxrpc "go.cryptoscope.co/muxrpc/v2"
|
|
|
|
"go.cryptoscope.co/muxrpc/v2/typemux"
|
|
|
|
|
|
|
|
"github.com/ssb-ngi-pointer/go-ssb-room/muxrpc/handlers/alias"
|
|
|
|
"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
|
2021-03-19 10:51:06 +00:00
|
|
|
func (s *Server) initHandlers(aliasDB roomdb.AliasesService) {
|
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"),
|
|
|
|
s.Whoami(),
|
|
|
|
s.StateManager,
|
|
|
|
)
|
|
|
|
|
|
|
|
aliasHandler := alias.New(
|
|
|
|
kitlog.With(s.logger, "unit", "aliases"),
|
|
|
|
s.Whoami(),
|
|
|
|
aliasDB,
|
2021-03-23 15:50:25 +00:00
|
|
|
s.domain,
|
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-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)
|
|
|
|
|
|
|
|
// 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))
|
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-11 17:40:33 +00:00
|
|
|
}
|
|
|
|
}
|