From 5f2d330f76b81ecd5be3ff19a8d8dd426b83504c Mon Sep 17 00:00:00 2001 From: Jeffrey Picard Date: Tue, 11 Oct 2022 22:30:54 +0000 Subject: [PATCH] more endpoints --- server/jsonrpc_server.go | 31 ++++++++++++++++++++++++++----- server/jsonrpc_service.go | 20 +++++++++++++++++--- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/server/jsonrpc_server.go b/server/jsonrpc_server.go index 52fa6f1..104fcac 100644 --- a/server/jsonrpc_server.go +++ b/server/jsonrpc_server.go @@ -1,12 +1,10 @@ package server import ( - "github.com/lbryio/herald.go/db" log "github.com/sirupsen/logrus" ) -type ServerService struct { - DB *db.ReadOnlyDBColumnFamily +type ServerFeatureService struct { Args *Args } @@ -28,7 +26,7 @@ type ServerFeaturesRes struct { } // Features is the json rpc endpoint for 'server.features'. -func (t *ServerService) Features(req *ServerFeaturesReq, res **ServerFeaturesRes) error { +func (t *ServerFeatureService) Features(req *ServerFeaturesReq, res **ServerFeaturesRes) error { log.Println("Features") features := &ServerFeaturesRes{ @@ -50,15 +48,38 @@ func (t *ServerService) Features(req *ServerFeaturesReq, res **ServerFeaturesRes return nil } +type ServerBannerService struct { + Args *Args +} + type ServerBannerReq struct{} type ServerBannerRes string // Banner is the json rpc endpoint for 'server.banner'. -func (t *ServerService) Banner(req *ServerBannerReq, res **ServerBannerRes) error { +func (t *ServerBannerService) Banner(req *ServerBannerReq, res **ServerBannerRes) error { log.Println("Banner") *res = (*ServerBannerRes)(t.Args.Banner) return nil } + +type ServerVersionService struct { + Args *Args +} + +type ServerVersionReq struct{} + +type ServerVersionRes string + +// Banner is the json rpc endpoint for 'server.version'. +// FIXME: This should return a struct with the version and the protocol version. +// <<-- that comment was written by github, scary shit because it's true +func (t *ServerVersionService) Version(req *ServerVersionReq, res **ServerVersionRes) error { + log.Println("Version") + + *res = (*ServerVersionRes)(&t.Args.ServerVersion) + + return nil +} diff --git a/server/jsonrpc_service.go b/server/jsonrpc_service.go index 46c7441..4955701 100644 --- a/server/jsonrpc_service.go +++ b/server/jsonrpc_service.go @@ -121,9 +121,23 @@ fail1: goto fail2 } - // Register "server.{features,version}"" handlers. - serverSvc := &ServerService{s.DB, s.Args} - err = s1.RegisterTCPService(serverSvc, "server") + // Register "server.{features,banner,version}" handlers. + serverFeatureSvc := &ServerFeatureService{s.Args} + err = s1.RegisterTCPService(serverFeatureSvc, "server_features") + if err != nil { + log.Errorf("RegisterTCPService: %v\n", err) + goto fail2 + } + + serverBannerSvc := &ServerBannerService{s.Args} + err = s1.RegisterTCPService(serverBannerSvc, "server_banner") + if err != nil { + log.Errorf("RegisterTCPService: %v\n", err) + goto fail2 + } + + serverVersionSvc := &ServerVersionService{s.Args} + err = s1.RegisterTCPService(serverVersionSvc, "server_version") if err != nil { log.Errorf("RegisterTCPService: %v\n", err) goto fail2