Skip to content

Commit

Permalink
Well... Starting the shit a bit slowly
Browse files Browse the repository at this point in the history
  • Loading branch information
0x19 committed Sep 15, 2024
1 parent decdf67 commit 309660d
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 2 deletions.
10 changes: 10 additions & 0 deletions cmd/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/unpackdev/fdb"
"github.com/urfave/cli/v2"
"log"
"runtime"
Expand All @@ -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()

Expand Down
16 changes: 16 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
25 changes: 23 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
Expand Down
22 changes: 22 additions & 0 deletions fdb.go
Original file line number Diff line number Diff line change
@@ -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
}
File renamed without changes.
8 changes: 8 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 309660d

Please sign in to comment.