From 309660d6b6daf46e2e4337b2ec1394b11ff3e9f8 Mon Sep 17 00:00:00 2001 From: Nevio Date: Sun, 15 Sep 2024 15:38:09 +0200 Subject: [PATCH] Well... Starting the shit a bit slowly --- cmd/benchmark.go | 10 +++++++++ cmd/server.go | 16 +++++++++++++ config.go | 25 +++++++++++++++++++-- entrypoint/main.go | 1 + fdb.go | 22 ++++++++++++++++++ manager_test.go => provider_manager_test.go | 0 types.go | 8 +++++++ 7 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 cmd/server.go create mode 100644 fdb.go rename manager_test.go => provider_manager_test.go (100%) diff --git a/cmd/benchmark.go b/cmd/benchmark.go index b7ddab7..6e2b914 100644 --- a/cmd/benchmark.go +++ b/cmd/benchmark.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "github.com/unpackdev/fdb" "github.com/urfave/cli/v2" "log" "runtime" @@ -17,6 +18,15 @@ func BenchmarkCommand() *cli.Command { // Simulate benchmarking logic here fmt.Println("Running client benchmark...") + cnf := fdb.Config{} + + fdbc, fdbcErr := fdb.New(c.Context, cnf) + if fdbcErr != nil { + return fdbcErr + } + + _ = fdbc + // Example: Perform a benchmark by running some mock client operations benchmarkClient() diff --git a/cmd/server.go b/cmd/server.go new file mode 100644 index 0000000..e2cfccf --- /dev/null +++ b/cmd/server.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/urfave/cli/v2" +) + +// ServerCommand returns a cli.Command that benchmarks the real client +func ServerCommand() *cli.Command { + return &cli.Command{ + Name: "server", + Usage: "Manage (f)db server", + Action: func(c *cli.Context) error { + return nil + }, + } +} diff --git a/config.go b/config.go index 419134f..380e7f9 100644 --- a/config.go +++ b/config.go @@ -7,11 +7,32 @@ type MdbxNode struct { type MdbxNodes []MdbxNode +type Transport struct { + Type TransportType `yaml:"type" json:"type" mapstructure:"type"` + Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"` + IPv4 string `yaml:"ipv4" json:"ipv4" mapstructure:"ipv4"` + Port int `yaml:"port" json:"port" mapstructure:"port"` +} + type Config struct { - MdbxNodes MdbxNodes `yaml:"nodes"` + Transports []Transport `yaml:"transports"` + MdbxNodes MdbxNodes `yaml:"nodes"` +} + +func (c Config) Validate() error { + return nil +} + +func (c Config) GetTransportByType(transportType TransportType) *Transport { + for _, t := range c.Transports { + if t.Type == transportType { + return &t + } + } + return nil } -func (c *Config) GetMdbxNodeByName(name string) *MdbxNode { +func (c Config) GetMdbxNodeByName(name string) *MdbxNode { for _, node := range c.MdbxNodes { if node.Name == name { return &node diff --git a/entrypoint/main.go b/entrypoint/main.go index e252168..5d19ae6 100644 --- a/entrypoint/main.go +++ b/entrypoint/main.go @@ -13,6 +13,7 @@ func main() { Usage: "Lorem ipsum dolor sit amet...", Commands: []*cli.Command{ // Load commands from the cmd package + cmd.ServerCommand(), cmd.BenchmarkCommand(), // Load the 'test' command }, } diff --git a/fdb.go b/fdb.go new file mode 100644 index 0000000..4bd3c49 --- /dev/null +++ b/fdb.go @@ -0,0 +1,22 @@ +package fdb + +import ( + "context" + "github.com/pkg/errors" +) + +type FDB struct { + ctx context.Context + config Config +} + +func New(ctx context.Context, config Config) (*FDB, error) { + if err := config.Validate(); err != nil { + return nil, errors.Wrap(err, "failure to validate (f)db configuration") + } + + return &FDB{ + ctx: ctx, + config: config, + }, nil +} diff --git a/manager_test.go b/provider_manager_test.go similarity index 100% rename from manager_test.go rename to provider_manager_test.go diff --git a/types.go b/types.go index 0c7fd19..16be9b6 100644 --- a/types.go +++ b/types.go @@ -2,6 +2,12 @@ package fdb import "fmt" +type TransportType string + +func (t TransportType) String() string { + return string(t) +} + type DbType string func (t DbType) String() string { @@ -15,6 +21,8 @@ type HandlerType byte const ( WriteHandlerType HandlerType = 'W' // 'W' for WRITE ReadHandlerType HandlerType = 'R' // 'R' for READ + + QuicTransportType TransportType = "QUIC" ) // FromByte converts a byte into a HandlerType