rocksdb #29

Merged
jeffreypicard merged 93 commits from feature/27/jeffreypicard/rocksdb into master 2022-04-29 17:04:01 +02:00
2 changed files with 35 additions and 0 deletions
Showing only changes of commit d68a67133b - Show all commits

View file

@ -41,6 +41,8 @@ type Args struct {
DisableRocksDBRefresh bool DisableRocksDBRefresh bool
DisableResolve bool DisableResolve bool
DisableBlockingAndFiltering bool DisableBlockingAndFiltering bool
BlockingChannelIds []string
FilteringChannelIds []string
} }
const ( const (
@ -65,6 +67,11 @@ const (
DefaultDisableBlockingAndFiltering = false DefaultDisableBlockingAndFiltering = false
) )
var (
DefaultBlockingChannelIds = []string{}
DefaultFilteringChannelIds = []string{}
)
// GetEnvironment takes the environment variables as an array of strings // GetEnvironment takes the environment variables as an array of strings
// and a getkeyval function to turn it into a map. // and a getkeyval function to turn it into a map.
func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string { func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string {
@ -109,6 +116,8 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
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})
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})
filteringChannelIds := parser.StringList("", "filtering-channel-ids", &argparse.Options{Required: false, Help: "Filtering channel ids", Default: DefaultFilteringChannelIds})
debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false}) debug := parser.Flag("", "debug", &argparse.Options{Required: false, Help: "enable debug logging", Default: false})
disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false}) disableEs := parser.Flag("", "disable-es", &argparse.Options{Required: false, Help: "Disable elastic search, for running/testing independently", Default: false})
@ -160,6 +169,8 @@ func ParseArgs(searchRequest *pb.SearchRequest) *Args {
DisableRocksDBRefresh: *disableRocksDBRefresh, DisableRocksDBRefresh: *disableRocksDBRefresh,
DisableResolve: *disableResolve, DisableResolve: *disableResolve,
DisableBlockingAndFiltering: *disableBlockingAndFiltering, DisableBlockingAndFiltering: *disableBlockingAndFiltering,
BlockingChannelIds: *blockingChannelIds,
FilteringChannelIds: *filteringChannelIds,
} }
if esHost, ok := environment["ELASTIC_HOST"]; ok { if esHost, ok := environment["ELASTIC_HOST"]; ok {

View file

@ -3,6 +3,7 @@ package server
import ( import (
"context" "context"
"crypto/sha256" "crypto/sha256"
"encoding/hex"
"fmt" "fmt"
"hash" "hash"
"log" "log"
@ -21,6 +22,7 @@ import (
"github.com/olivere/elastic/v7" "github.com/olivere/elastic/v7"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
logrus "github.com/sirupsen/logrus"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"
) )
@ -196,6 +198,28 @@ func MakeHubServer(ctx context.Context, args *Args) *Server {
// Can't load the db, fail loudly // Can't load the db, fail loudly
log.Fatalln(err) log.Fatalln(err)
} }
blockingChannelHashes := make([][]byte, 0, 10)
filteringChannelHashes := make([][]byte, 0, 10)
for _, id := range args.BlockingChannelIds {
hash, err := hex.DecodeString(id)
if err != nil {
logrus.Warn("Invalid channel id: ", id)
}
blockingChannelHashes = append(blockingChannelHashes, hash)
}
for _, id := range args.FilteringChannelIds {
hash, err := hex.DecodeString(id)
if err != nil {
logrus.Warn("Invalid channel id: ", id)
}
filteringChannelHashes = append(filteringChannelHashes, hash)
}
myDB.BlockingChannelHashes = blockingChannelHashes
myDB.FilteringChannelHashes = filteringChannelHashes
} }
s := &Server{ s := &Server{