File tree Expand file tree Collapse file tree 13 files changed +245
-61
lines changed Expand file tree Collapse file tree 13 files changed +245
-61
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ package cmd
3
3
import (
4
4
"fmt"
5
5
"github.com/unpackdev/fdb"
6
+ "github.com/unpackdev/fdb/pkg/config"
7
+ "github.com/unpackdev/fdb/pkg/types"
6
8
"github.com/urfave/cli/v2"
7
9
"log"
8
10
"runtime"
@@ -18,7 +20,20 @@ func BenchmarkCommand() *cli.Command {
18
20
// Simulate benchmarking logic here
19
21
fmt .Println ("Running client benchmark..." )
20
22
21
- cnf := fdb.Config {}
23
+ cnf := config.Config {
24
+ Transports : []config.Transport {
25
+ {
26
+ Type : types .QUICTransportType ,
27
+ Enabled : true ,
28
+ Config : config.QuicTransport {IPv4 : "127.0.0.1" , Port : 4433 },
29
+ },
30
+ /* {
31
+ Type: fdb.UDS,
32
+ Enabled: true,
33
+ Config: fdb.UdsTransport{IPv4: "127.0.0.1", Port: 8000},
34
+ },*/
35
+ },
36
+ }
22
37
23
38
fdbc , fdbcErr := fdb .New (c .Context , cnf )
24
39
if fdbcErr != nil {
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -3,14 +3,15 @@ package fdb
3
3
import (
4
4
"context"
5
5
"github.com/pkg/errors"
6
+ "github.com/unpackdev/fdb/pkg/config"
6
7
)
7
8
8
9
type FDB struct {
9
10
ctx context.Context
10
- config Config
11
+ config config. Config
11
12
}
12
13
13
- func New (ctx context.Context , config Config ) (* FDB , error ) {
14
+ func New (ctx context.Context , config config. Config ) (* FDB , error ) {
14
15
if err := config .Validate (); err != nil {
15
16
return nil , errors .Wrap (err , "failure to validate (f)db configuration" )
16
17
}
Original file line number Diff line number Diff line change @@ -4,17 +4,18 @@ import (
4
4
"context"
5
5
"github.com/erigontech/mdbx-go/mdbx"
6
6
"github.com/pkg/errors"
7
+ "github.com/unpackdev/fdb/pkg/config"
7
8
"os"
8
9
)
9
10
10
11
type Db struct {
11
12
ctx context.Context
12
- opts MdbxNode
13
+ opts config. MdbxNode
13
14
env * mdbx.Env
14
15
dbi mdbx.DBI
15
16
}
16
17
17
- func NewDb (ctx context.Context , opts MdbxNode ) (Provider , error ) {
18
+ func NewDb (ctx context.Context , opts config. MdbxNode ) (Provider , error ) {
18
19
env , err := mdbx .NewEnv ()
19
20
if err != nil {
20
21
return nil , err
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import "github.com/unpackdev/fdb/pkg/types"
4
+
5
+ type Config struct {
6
+ Transports []Transport `yaml:"transports"`
7
+ MdbxNodes MdbxNodes `yaml:"nodes"`
8
+ }
9
+
10
+ func (c Config ) Validate () error {
11
+ return nil
12
+ }
13
+
14
+ func (c Config ) GetTransportByType (transportType types.TransportType ) * Transport {
15
+ for _ , t := range c .Transports {
16
+ if t .Type == transportType {
17
+ return & t
18
+ }
19
+ }
20
+ return nil
21
+ }
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ // MdbxNode and MdbxNodes as before
4
+ type MdbxNode struct {
5
+ Name string `yaml:"name"`
6
+ Path string `yaml:"path"`
7
+ }
8
+
9
+ type MdbxNodes []MdbxNode
10
+
11
+ func (c Config ) GetMdbxNodeByName (name string ) * MdbxNode {
12
+ for _ , node := range c .MdbxNodes {
13
+ if node .Name == name {
14
+ return & node
15
+ }
16
+ }
17
+ return nil
18
+ }
Original file line number Diff line number Diff line change
1
+ package config
2
+
3
+ import "github.com/unpackdev/fdb/pkg/types"
4
+
5
+ type TransportConfig interface {
6
+ GetTransportType () types.TransportType
7
+ }
8
+
9
+ type Transport struct {
10
+ Type types.TransportType
11
+ Enabled bool
12
+ Config TransportConfig
13
+ }
14
+
15
+ // QuicTransport implements TransportConfig
16
+ type QuicTransport struct {
17
+ Type types.TransportType `yaml:"type" json:"type" mapstructure:"type"`
18
+ Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"`
19
+ IPv4 string `yaml:"ipv4" json:"ipv4" mapstructure:"ipv4"`
20
+ Port int `yaml:"port" json:"port" mapstructure:"port"`
21
+ }
22
+
23
+ func (q QuicTransport ) GetTransportType () types.TransportType {
24
+ return q .Type
25
+ }
26
+
27
+ // UdsTransport implements TransportConfig
28
+ type UdsTransport struct {
29
+ Type types.TransportType `yaml:"type" json:"type" mapstructure:"type"`
30
+ Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"`
31
+ IPv4 string `yaml:"ipv4" json:"ipv4" mapstructure:"ipv4"`
32
+ Port int `yaml:"port" json:"port" mapstructure:"port"`
33
+ }
34
+
35
+ func (u UdsTransport ) GetTransportType () types.TransportType {
36
+ return u .Type
37
+ }
Original file line number Diff line number Diff line change
1
+ package types
2
+
3
+ import "fmt"
4
+
5
+ type TransportType int
6
+
7
+ const (
8
+ UDPTransportType TransportType = iota
9
+ QUICTransportType
10
+ UDSTransportType
11
+ TCPTransportType
12
+ )
13
+
14
+ type DbType string
15
+
16
+ func (t DbType ) String () string {
17
+ return string (t )
18
+ }
19
+
20
+ const (
21
+ // To be defined for database types in the future...
22
+ )
23
+
24
+ // HandlerType represents different types of handlers
25
+ type HandlerType byte
26
+
27
+ // FromByte converts a byte into a HandlerType
28
+ func (h * HandlerType ) FromByte (b byte ) error {
29
+ switch b {
30
+ case 'W' :
31
+ * h = WriteHandlerType
32
+ case 'R' :
33
+ * h = ReadHandlerType
34
+ default :
35
+ return fmt .Errorf ("invalid action byte: %v" , b )
36
+ }
37
+ return nil
38
+ }
39
+
40
+ // Define the handlers as 1-byte constants
41
+ const (
42
+ WriteHandlerType HandlerType = 'W' // 'W' for WRITE
43
+ ReadHandlerType HandlerType = 'R' // 'R' for READ
44
+ )
Original file line number Diff line number Diff line change @@ -3,15 +3,16 @@ package fdb
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "github.com/unpackdev/fdb/pkg/config"
6
7
)
7
8
8
9
type Manager struct {
9
10
ctx context.Context
10
- opts MdbxNodes
11
+ opts config. MdbxNodes
11
12
dbs map [DbType ]Provider
12
13
}
13
14
14
- func NewManager (ctx context.Context , opts MdbxNodes ) (* Manager , error ) {
15
+ func NewManager (ctx context.Context , opts config. MdbxNodes ) (* Manager , error ) {
15
16
dbs := make (map [DbType ]Provider )
16
17
for _ , node := range opts {
17
18
db , err := NewDb (ctx , node )
Original file line number Diff line number Diff line change @@ -15,6 +15,25 @@ import (
15
15
// Handler function type for QUIC
16
16
type QuicHandler func (sess quic.Connection , stream quic.Stream , message * Message )
17
17
18
+ type QuicConfig struct {
19
+ Type TransportType `yaml:"type" json:"type" mapstructure:"type"`
20
+ Enabled bool `yaml:"enabled" json:"enabled" mapstructure:"enabled"`
21
+ IPv4 string `yaml:"ipv4" json:"ipv4" mapstructure:"ipv4"`
22
+ Port int `yaml:"port" json:"port" mapstructure:"port"`
23
+ }
24
+
25
+ func (c QuicConfig ) GetType () TransportType {
26
+ return c .Type
27
+ }
28
+
29
+ func (c QuicConfig ) IsEnabled () bool {
30
+ return c .Enabled
31
+ }
32
+
33
+ func (c QuicConfig ) IsIPv4 () bool {
34
+ return c .IPv4 != ""
35
+ }
36
+
18
37
// QuicServer struct represents the QUIC server
19
38
type QuicServer struct {
20
39
handlerRegistry map [HandlerType ]QuicHandler
You can’t perform that action at this time.
0 commit comments