debug server
This commit is contained in:
parent
33cbdd06a6
commit
f9cb0c2dbb
9
net/rpc/debugserver/config.go
Normal file
9
net/rpc/debugserver/config.go
Normal file
@ -0,0 +1,9 @@
|
||||
package debugserver
|
||||
|
||||
type configGetter interface {
|
||||
GetDebugServer() Config
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ListenAddr string `yaml:"listenAddr"`
|
||||
}
|
||||
63
net/rpc/debugserver/debugserver.go
Normal file
63
net/rpc/debugserver/debugserver.go
Normal file
@ -0,0 +1,63 @@
|
||||
package debugserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/anyproto/any-sync/app"
|
||||
"github.com/anyproto/any-sync/net/rpc"
|
||||
"net"
|
||||
"storj.io/drpc"
|
||||
"storj.io/drpc/drpcmanager"
|
||||
"storj.io/drpc/drpcmux"
|
||||
"storj.io/drpc/drpcserver"
|
||||
"storj.io/drpc/drpcstream"
|
||||
"storj.io/drpc/drpcwire"
|
||||
)
|
||||
|
||||
const CName = "net.rpc.debugserver"
|
||||
|
||||
type DebugServer interface {
|
||||
app.ComponentRunnable
|
||||
drpc.Mux
|
||||
}
|
||||
|
||||
type debugServer struct {
|
||||
drpcServer *drpcserver.Server
|
||||
*drpcmux.Mux
|
||||
drpcConf rpc.Config
|
||||
config Config
|
||||
runCtx context.Context
|
||||
runCtxCancel context.CancelFunc
|
||||
}
|
||||
|
||||
func (d *debugServer) Init(a *app.App) (err error) {
|
||||
d.drpcConf = a.MustComponent("config").(rpc.ConfigGetter).GetDrpc()
|
||||
d.config = a.MustComponent("config").(configGetter).GetDebugServer()
|
||||
d.Mux = drpcmux.New()
|
||||
bufSize := d.drpcConf.Stream.MaxMsgSizeMb * (1 << 20)
|
||||
d.drpcServer = drpcserver.NewWithOptions(d, drpcserver.Options{Manager: drpcmanager.Options{
|
||||
Reader: drpcwire.ReaderOptions{MaximumBufferSize: bufSize},
|
||||
Stream: drpcstream.Options{MaximumBufferSize: bufSize},
|
||||
}})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *debugServer) Name() (name string) {
|
||||
return CName
|
||||
}
|
||||
|
||||
func (d *debugServer) Run(ctx context.Context) (err error) {
|
||||
lis, err := net.Listen("tpc", d.config.ListenAddr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
d.runCtx, d.runCtxCancel = context.WithCancel(context.Background())
|
||||
go d.drpcServer.Serve(d.runCtx, lis)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *debugServer) Close(ctx context.Context) (err error) {
|
||||
if d.runCtx != nil {
|
||||
d.runCtxCancel()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user