server.banner

This commit is contained in:
Jeffrey Picard 2022-10-11 14:29:51 +00:00
parent 66961c1e3d
commit 698bc22360
2 changed files with 45 additions and 27 deletions

View file

@ -1,6 +1,7 @@
package server package server
import ( import (
"fmt"
"log" "log"
"os" "os"
"strconv" "strconv"
@ -36,6 +37,7 @@ type Args struct {
RefreshDelta int RefreshDelta int
CacheTTL int CacheTTL int
PeerFile string PeerFile string
Banner *string
Country string Country string
BlockingChannelIds []string BlockingChannelIds []string
FilteringChannelIds []string FilteringChannelIds []string
@ -78,6 +80,7 @@ const (
DefaultRefreshDelta = 5 DefaultRefreshDelta = 5
DefaultCacheTTL = 5 DefaultCacheTTL = 5
DefaultPeerFile = "peers.txt" DefaultPeerFile = "peers.txt"
DefaultBannerFile = ""
DefaultCountry = "US" DefaultCountry = "US"
GENESIS_HASH = "9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f463" GENESIS_HASH = "9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f463"
@ -106,6 +109,26 @@ var (
DefaultFilteringChannelIds = []string{} DefaultFilteringChannelIds = []string{}
) )
func loadBanner(bannerFile *string, serverVersion string) *string {
var banner string
data, err := os.ReadFile(*bannerFile)
if err != nil {
banner = fmt.Sprintf("You are connected to an %s server.", serverVersion)
} else {
banner = string(data)
}
/*
banner := os.Getenv("BANNER")
if banner == "" {
return nil
}
*/
return &banner
}
// MakeDefaultArgs creates a default set of arguments for testing the server. // MakeDefaultArgs creates a default set of arguments for testing the server.
func MakeDefaultTestArgs() *Args { func MakeDefaultTestArgs() *Args {
args := &Args{ args := &Args{
@ -122,6 +145,7 @@ func MakeDefaultTestArgs() *Args {
RefreshDelta: DefaultRefreshDelta, RefreshDelta: DefaultRefreshDelta,
CacheTTL: DefaultCacheTTL, CacheTTL: DefaultCacheTTL,
PeerFile: DefaultPeerFile, PeerFile: DefaultPeerFile,
Banner: nil,
Country: DefaultCountry, Country: DefaultCountry,
GenesisHash: GENESIS_HASH, GenesisHash: GENESIS_HASH,
@ -203,6 +227,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
refreshDelta := parser.Int("", "refresh-delta", &argparse.Options{Required: false, Help: "elasticsearch index refresh delta in seconds", Default: DefaultRefreshDelta}) refreshDelta := parser.Int("", "refresh-delta", &argparse.Options{Required: false, Help: "elasticsearch index refresh delta in seconds", Default: DefaultRefreshDelta})
cacheTTL := parser.Int("", "cachettl", &argparse.Options{Required: false, Help: "Cache TTL in minutes", Default: DefaultCacheTTL}) cacheTTL := parser.Int("", "cachettl", &argparse.Options{Required: false, Help: "Cache TTL in minutes", Default: DefaultCacheTTL})
peerFile := parser.String("", "peerfile", &argparse.Options{Required: false, Help: "Initial peer file for federation", Default: DefaultPeerFile}) peerFile := parser.String("", "peerfile", &argparse.Options{Required: false, Help: "Initial peer file for federation", Default: DefaultPeerFile})
bannerFile := parser.String("", "bannerfile", &argparse.Options{Required: false, Help: "Banner file server.banner", Default: DefaultBannerFile})
country := parser.String("", "country", &argparse.Options{Required: false, Help: "Country this node is running in. Default US.", Default: DefaultCountry}) country := parser.String("", "country", &argparse.Options{Required: false, Help: "Country this node is running in. Default US.", Default: DefaultCountry})
blockingChannelIds := parser.StringList("", "blocking-channel-ids", &argparse.Options{Required: false, Help: "Blocking channel ids", Default: DefaultBlockingChannelIds}) blockingChannelIds := parser.StringList("", "blocking-channel-ids", &argparse.Options{Required: false, Help: "Blocking channel ids", Default: DefaultBlockingChannelIds})
filteringChannelIds := parser.StringList("", "filtering-channel-ids", &argparse.Options{Required: false, Help: "Filtering channel ids", Default: DefaultFilteringChannelIds}) filteringChannelIds := parser.StringList("", "filtering-channel-ids", &argparse.Options{Required: false, Help: "Filtering channel ids", Default: DefaultFilteringChannelIds})
@ -249,6 +274,8 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
*jsonRPCPort = DefaultJSONRPCPort *jsonRPCPort = DefaultJSONRPCPort
} }
banner := loadBanner(bannerFile, HUB_PROTOCOL_VERSION)
args := &Args{ args := &Args{
CmdType: SearchCmd, CmdType: SearchCmd,
Host: *host, Host: *host,
@ -267,6 +294,7 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
RefreshDelta: *refreshDelta, RefreshDelta: *refreshDelta,
CacheTTL: *cacheTTL, CacheTTL: *cacheTTL,
PeerFile: *peerFile, PeerFile: *peerFile,
Banner: banner,
Country: *country, Country: *country,
BlockingChannelIds: *blockingChannelIds, BlockingChannelIds: *blockingChannelIds,
FilteringChannelIds: *filteringChannelIds, FilteringChannelIds: *filteringChannelIds,

View file

@ -5,13 +5,6 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// const (
// GENESIS_HASH = "9c89283ba0f3227f6c03b70216b9f665f0118d5e0fa729cedf4fb34d6a34f463"
// HUB_PROTOCOL_VERSION = "0.107.0"
// PROTOCOL_MIN = "0.54.0"
// PROTOCOL_MAX = "0.199.0"
// )
type ServerService struct { type ServerService struct {
DB *db.ReadOnlyDBColumnFamily DB *db.ReadOnlyDBColumnFamily
Args *Args Args *Args
@ -19,22 +12,6 @@ type ServerService struct {
type ServerFeaturesReq struct{} type ServerFeaturesReq struct{}
/*
cls.cached_server_features.update({
'hosts': {},
'pruning': None,
'server_version': cls.version,
'protocol_min': min_str,
'protocol_max': max_str,
'genesis_hash': env.coin.GENESIS_HASH,
'description': env.description,
'payment_address': env.payment_address,
'donation_address': env.donation_address,
'daily_fee': env.daily_fee,
'hash_function': 'sha256',
'trending_algorithm': 'fast_ar'
})
*/
type ServerFeaturesRes struct { type ServerFeaturesRes struct {
Hosts map[string]string `json:"hosts"` Hosts map[string]string `json:"hosts"`
Pruning string `json:"pruning"` Pruning string `json:"pruning"`
@ -61,10 +38,10 @@ func (t *ServerService) Features(req *ServerFeaturesReq, res **ServerFeaturesRes
ProtocolMin: PROTOCOL_MIN, ProtocolMin: PROTOCOL_MIN,
ProtocolMax: PROTOCOL_MAX, ProtocolMax: PROTOCOL_MAX,
GenesisHash: GENESIS_HASH, GenesisHash: GENESIS_HASH,
Description: "Herald", Description: t.Args.ServerDescription,
PaymentAddress: "", PaymentAddress: t.Args.PaymentAddress,
DonationAddress: "", DonationAddress: t.Args.DonationAddress,
DailyFee: "1.0", DailyFee: t.Args.DailyFee,
HashFunction: "sha256", HashFunction: "sha256",
TrendingAlgorithm: "fast_ar", TrendingAlgorithm: "fast_ar",
} }
@ -72,3 +49,16 @@ func (t *ServerService) Features(req *ServerFeaturesReq, res **ServerFeaturesRes
return nil return nil
} }
type ServerBannerReq struct{}
type ServerBannerRes string
// Banner is the json rpc endpoint for 'server.banner'.
func (t *ServerService) Banner(req *ServerBannerReq, res **ServerBannerRes) error {
log.Println("Banner")
*res = (*ServerBannerRes)(t.Args.Banner)
return nil
}