From 58e8f78c5657a2e2714340ff5e65bc82955d5ba2 Mon Sep 17 00:00:00 2001 From: eyedeekay Date: Sat, 29 Jun 2024 00:23:42 -0400 Subject: [PATCH] Start making it so I can configure things, so I can configure it to read the netDb I already have and attempt to make a connection. Implement a reseed puller, or at least most of one. --- README.md | 2 +- go.mod | 12 +++- go.sum | 46 ------------ lib/config/netdb.go | 2 +- lib/config/router.go | 35 ++++++++- lib/netdb/std.go | 3 + lib/router/router.go | 5 +- lib/transport/noise/client_handshake.go | 15 ---- lib/transport/noise/client_session.go | 75 ------------------- lib/transport/noise/handshake.go | 41 ----------- lib/transport/noise/session.go | 85 ---------------------- lib/transport/noise/transport.go | 96 ------------------------- lib/transport/noise/transport_test.go | 16 ----- main.go | 6 ++ 14 files changed, 57 insertions(+), 382 deletions(-) delete mode 100644 lib/transport/noise/client_handshake.go delete mode 100644 lib/transport/noise/client_session.go delete mode 100644 lib/transport/noise/handshake.go delete mode 100644 lib/transport/noise/session.go delete mode 100644 lib/transport/noise/transport.go delete mode 100644 lib/transport/noise/transport_test.go diff --git a/README.md b/README.md index ee5d747..e8abaeb 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ please keep up with these changes, as they will not be backward compatible and r - [ ] Tunnel Message Crypto - [ ] Tunnel Message Fragmentation/Reassembly - Common Data Structures - - [/] Keys and Cert + - [X] Keys and Cert - [X] Key Certificates - [X] Certificate - [X] Lease diff --git a/go.mod b/go.mod index 4596d94..21f45d4 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,17 @@ module github.com/go-i2p/go-i2p -go 1.16 +go 1.21 require ( - github.com/emirpasic/gods v1.18.1 - github.com/flynn/noise v1.1.0 github.com/sirupsen/logrus v1.9.3 github.com/stretchr/testify v1.7.0 golang.org/x/crypto v0.23.0 ) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + golang.org/x/sys v0.20.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) diff --git a/go.sum b/go.sum index 68dc176..ba6d5b5 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,6 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= -github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= -github.com/flynn/noise v1.1.0 h1:KjPQoQCEFdZDiP03phOvGi11+SVVhBG2wOWAorLsstg= -github.com/flynn/noise v1.1.0/go.mod h1:xbMo+0i6+IGbYdJhF31t2eR1BIU0CYc12+BNAKwUTag= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -17,53 +13,11 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= -golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= -golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= -golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/lib/config/netdb.go b/lib/config/netdb.go index 7dd3d09..5256e47 100644 --- a/lib/config/netdb.go +++ b/lib/config/netdb.go @@ -12,5 +12,5 @@ type NetDbConfig struct { // default settings for netdb var DefaultNetDbConfig = NetDbConfig{ - Path: filepath.Join(".", "netDb"), + Path: filepath.Join(defaultConfig(), "netDb"), } diff --git a/lib/config/router.go b/lib/config/router.go index eb87ab1..a1ec8d6 100644 --- a/lib/config/router.go +++ b/lib/config/router.go @@ -1,15 +1,48 @@ package config +import ( + "os" + "path/filepath" +) + // router.config options type RouterConfig struct { + // the path to the base config directory where per-system defaults are stored + BaseDir string + // the path to the working config directory where files are changed + WorkingDir string // netdb configuration NetDb *NetDbConfig // configuration for bootstrapping into the network Bootstrap *BootstrapConfig } +func home() string { + h, err := os.UserHomeDir() + if err != nil { + panic(err) + } + return h +} + +func defaultBase() string { + return filepath.Join(home(), "go-i2p", "base") +} + +func defaultConfig() string { + return filepath.Join(home(), "go-i2p", "config") +} + // defaults for router -var DefaultRouterConfig = &RouterConfig{ +var defaultRouterConfig = &RouterConfig{ NetDb: &DefaultNetDbConfig, Bootstrap: &DefaultBootstrapConfig, + BaseDir: defaultBase(), + WorkingDir: defaultConfig(), } + +func DefaultRouterConfig() *RouterConfig { + return defaultRouterConfig +} + +var RouterConfigProperties = DefaultRouterConfig() \ No newline at end of file diff --git a/lib/netdb/std.go b/lib/netdb/std.go index 82c54e5..0064885 100644 --- a/lib/netdb/std.go +++ b/lib/netdb/std.go @@ -145,6 +145,9 @@ func (db StdNetDB) SaveEntry(e *Entry) (err error) { // reseed if we have less than minRouters known routers // returns error if reseed failed func (db StdNetDB) Reseed(b bootstrap.Bootstrap, minRouters int) (err error) { + if db.Size() > minRouters { + return nil + } return } diff --git a/lib/router/router.go b/lib/router/router.go index 92a3e4b..83e88d7 100644 --- a/lib/router/router.go +++ b/lib/router/router.go @@ -1,10 +1,11 @@ package router import ( + "time" + "github.com/go-i2p/go-i2p/lib/config" "github.com/go-i2p/go-i2p/lib/netdb" log "github.com/sirupsen/logrus" - "time" ) // i2p router type @@ -17,7 +18,7 @@ type Router struct { // create router with default configuration func CreateRouter() (r *Router, err error) { - cfg := config.DefaultRouterConfig + cfg := config.RouterConfigProperties r, err = FromConfig(cfg) return } diff --git a/lib/transport/noise/client_handshake.go b/lib/transport/noise/client_handshake.go deleted file mode 100644 index de3d9d3..0000000 --- a/lib/transport/noise/client_handshake.go +++ /dev/null @@ -1,15 +0,0 @@ -package noise - -import ( - "github.com/flynn/noise" -) - -func ComposeInitiatorHandshakeMessage(s noise.DHKey, rs []byte, payload []byte, ePrivate []byte) (negData, msg []byte, state *noise.HandshakeState, err error) { - - return -} - -func (c *NoiseSession) RunClientHandshake() error { - - return nil -} diff --git a/lib/transport/noise/client_session.go b/lib/transport/noise/client_session.go deleted file mode 100644 index 6799b3f..0000000 --- a/lib/transport/noise/client_session.go +++ /dev/null @@ -1,75 +0,0 @@ -package noise - -import ( - "errors" - "sync/atomic" - - log "github.com/sirupsen/logrus" -) - -func (c *NoiseSession) Write(b []byte) (int, error) { - // interlock with Close below - for { - x := atomic.LoadInt32(&c.activeCall) - if x&1 != 0 { - log.WithFields(log.Fields{ - "at": "(NoiseSession) Write", - "reason": "session is closed", - }).Error("session is closed") - return 0, errors.New("session is closed") - } - if atomic.CompareAndSwapInt32(&c.activeCall, x, x+2) { - defer atomic.AddInt32(&c.activeCall, -2) - break - } - } - if err := c.RunClientHandshake(); err != nil { - return 0, err - } - c.Mutex.Lock() - defer c.Mutex.Unlock() - if !c.handshakeComplete { - return 0, errors.New("internal error") - } - n, err := c.writePacketLocked(b) - return n, err -} - -func (c *NoiseSession) writePacketLocked(data []byte) (int, error) { - var n int - if len(data) == 0 { //special case to answer when everything is ok during handshake - if _, err := c.Conn.Write(make([]byte, 2)); err != nil { - return 0, err - } - } - for len(data) > 0 { - /*m := len(data) - packet := c.InitializePacket() - maxPayloadSize := c.maxPayloadSizeForWrite(packet) - if m > int(maxPayloadSize) { - m = int(maxPayloadSize) - } - if c.CipherState != nil { - ////fmt.Println("writing encrypted packet:", m) - packet.reserve(uint16Size + uint16Size + m + macSize) - packet.resize(uint16Size + uint16Size + m) - copy(packet.data[uint16Size+uint16Size:], data[:m]) - binary.BigEndian.PutUint16(packet.data[uint16Size:], uint16(m)) - //fmt.Println("encrypt size", uint16(m)) - } else { - packet.resize(len(packet.data) + len(data)) - copy(packet.data[uint16Size:len(packet.data)], data[:m]) - binary.BigEndian.PutUint16(packet.data, uint16(len(data))) - } - b := c.encryptIfNeeded(packet) - c.freeBlock(packet) - ////fmt.Println(hex.EncodeToString(b)) - if _, err := c.conn.Write(b); err != nil { - return n, err - } - n += m - data = data[m:] - */ - } - return n, nil -} diff --git a/lib/transport/noise/handshake.go b/lib/transport/noise/handshake.go deleted file mode 100644 index 59cc91a..0000000 --- a/lib/transport/noise/handshake.go +++ /dev/null @@ -1,41 +0,0 @@ -package noise - -import ( - "sync" - - "github.com/go-i2p/go-i2p/lib/common/router_info" -) - -func (c *NoiseTransport) Handshake(routerInfo router_info.RouterInfo) error { - c.Mutex.Lock() - defer c.Mutex.Unlock() - session, err := c.GetSession(routerInfo) - if err != nil { - return err - } - for { - if session.(*NoiseSession).handshakeComplete { - return nil - } - if session.(*NoiseSession).Cond == nil { - break - } - session.(*NoiseSession).Cond.Wait() - } - // Set handshakeCond to indicate that this goroutine is committing to - // running the handshake. - session.(*NoiseSession).Cond = sync.NewCond(&c.Mutex) - c.Mutex.Unlock() - session.(*NoiseSession).Mutex.Lock() - defer session.(*NoiseSession).Mutex.Unlock() - c.Mutex.Lock() - // if c.config.isClient { - if err := session.(*NoiseSession).RunClientHandshake(); err != nil { - return err - } - // Wake any other goroutines that are waiting for this handshake to - // complete. - session.(*NoiseSession).Cond.Broadcast() - session.(*NoiseSession).Cond = nil - return nil -} diff --git a/lib/transport/noise/session.go b/lib/transport/noise/session.go deleted file mode 100644 index ad7df4a..0000000 --- a/lib/transport/noise/session.go +++ /dev/null @@ -1,85 +0,0 @@ -package noise - -import ( - "bytes" - "net" - "sync" - "time" - - cb "github.com/emirpasic/gods/queues/circularbuffer" - "github.com/flynn/noise" - - "github.com/go-i2p/go-i2p/lib/common/router_info" - "github.com/go-i2p/go-i2p/lib/i2np" - "github.com/go-i2p/go-i2p/lib/transport" -) - -type NoiseSession struct { - *cb.Queue - router_info.RouterInfo - *noise.CipherState - sync.Mutex - *sync.Cond - *NoiseTransport - handshakeBuffer bytes.Buffer - activeCall int32 - handshakeComplete bool - Conn net.Conn -} - -// Read implements net.Conn -func (*NoiseSession) Read(b []byte) (n int, err error) { - panic("unimplemented") -} - -// RemoteAddr implements net.Conn -func (*NoiseSession) RemoteAddr() net.Addr { - panic("unimplemented") -} - -// SetDeadline implements net.Conn -func (*NoiseSession) SetDeadline(t time.Time) error { - panic("unimplemented") -} - -// SetReadDeadline implements net.Conn -func (*NoiseSession) SetReadDeadline(t time.Time) error { - panic("unimplemented") -} - -// SetWriteDeadline implements net.Conn -func (*NoiseSession) SetWriteDeadline(t time.Time) error { - panic("unimplemented") -} - -var exampleNoiseSession transport.TransportSession = &NoiseSession{} -var ExampleNoiseSession net.Conn = exampleNoiseSession.(*NoiseSession) - -func (s *NoiseSession) LocalAddr() net.Addr { - return s.Conn.LocalAddr() -} - -func (s *NoiseSession) QueueSendI2NP(msg i2np.I2NPMessage) { - s.Queue.Enqueue(msg) -} - -func (s *NoiseSession) SendQueueSize() int { - return s.Queue.Size() -} - -func (s *NoiseSession) ReadNextI2NP() (i2np.I2NPMessage, error) { - return i2np.I2NPMessage{}, nil -} - -func (s *NoiseSession) Close() error { - s.Queue.Clear() - return nil -} - -func NewNoiseTransportSession(ri router_info.RouterInfo, socket net.Conn) (transport.TransportSession, error) { - return &NoiseSession{ - Queue: cb.New(1024), - RouterInfo: ri, - Conn: socket, - }, nil -} diff --git a/lib/transport/noise/transport.go b/lib/transport/noise/transport.go deleted file mode 100644 index 66532ce..0000000 --- a/lib/transport/noise/transport.go +++ /dev/null @@ -1,96 +0,0 @@ -package noise - -/** - * NoiseTransport is an unused transport which is used only for testing the - * transport interfaces. I2P adds obfuscation to NOISE with the NTCP2 protocol - * which is one of the transports which we use in practice. -**/ - -import ( - "errors" - "net" - "sync" - - "github.com/flynn/noise" - "github.com/go-i2p/go-i2p/lib/common/data" - "github.com/go-i2p/go-i2p/lib/common/router_identity" - "github.com/go-i2p/go-i2p/lib/common/router_info" - "github.com/go-i2p/go-i2p/lib/transport" -) - -type NoiseTransport struct { - *noise.CipherState - router_identity.RouterIdentity - sync.Mutex - Listener net.Listener - peerConnections map[data.Hash]transport.TransportSession -} - -var exampleNoiseTransport transport.Transport = &NoiseTransport{} - -// ExampleNoiseListener is not a real Noise Listener, do not use it. -// It is exported so that it can be confirmed that the transport -// implements net.Listener -var ExampleNoiseListener net.Listener = exampleNoiseTransport - -func (noopt *NoiseTransport) Accept() (net.Conn, error) { - return noopt.Listener.Accept() -} - -func (noopt *NoiseTransport) Addr() net.Addr { - return noopt.Listener.Addr() -} - -func (noopt *NoiseTransport) Name() string { - return "noise" -} - -// Set the router identity for this transport. -// will bind if the underlying socket is not already -// if the underlying socket is already bound update the RouterIdentity -// returns any errors that happen if they do -func (noopt *NoiseTransport) SetIdentity(ident router_identity.RouterIdentity) error { - noopt.RouterIdentity = ident - return nil -} - -// Obtain a transport session with a router given its RouterInfo. -// If a session with this router is NOT already made attempt to create one and block until made or until an error happens -// returns an established TransportSession and nil on success -// returns nil and an error on error -func (noopt *NoiseTransport) GetSession(routerInfo router_info.RouterInfo) (transport.TransportSession, error) { - hash := routerInfo.IdentHash() - if len(hash) == 0 { - return nil, errors.New("NoiseTransport: GetSession: RouterInfo has no IdentityHash") - } - if t, ok := noopt.peerConnections[hash]; ok == true { - return t, nil - } - conn, err := noopt.Accept() - if err == nil { - if noopt.peerConnections[hash], err = NewNoiseTransportSession(routerInfo, conn); err != nil { - return noopt.peerConnections[hash], err - } - } - return nil, err -} - -// return true if a routerInfo is compatable with this transport -func (noopt *NoiseTransport) Compatable(routerInfo router_info.RouterInfo) bool { - _, ok := noopt.peerConnections[routerInfo.IdentHash()] - return ok -} - -// close the transport cleanly -// blocks until done -// returns an error if one happens -func (noopt *NoiseTransport) Close() error { - return nil -} - -func NewNoiseTransport(netSocket net.Listener) *NoiseTransport { - return &NoiseTransport{ - peerConnections: make(map[data.Hash]transport.TransportSession), - Listener: netSocket, - } -} diff --git a/lib/transport/noise/transport_test.go b/lib/transport/noise/transport_test.go deleted file mode 100644 index 290dde4..0000000 --- a/lib/transport/noise/transport_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package noise - -import ( - "net" - "testing" -) - -func TestTransport(t *testing.T) { - ln, err := net.Listen("tcp", ":42069") - if err != nil { - t.Error(err) - } - nt := NewNoiseTransport(ln) - - t.Log(nt.Name()) -} diff --git a/main.go b/main.go index 100eb1e..f093c23 100644 --- a/main.go +++ b/main.go @@ -1,12 +1,18 @@ package main import ( + "github.com/go-i2p/go-i2p/lib/config" "github.com/go-i2p/go-i2p/lib/router" "github.com/go-i2p/go-i2p/lib/util/signals" log "github.com/sirupsen/logrus" + + "flag" ) func main() { + netDbPath := flag.String("netDb", config.DefaultNetDbConfig.Path, "Path to the netDb") + flag.Parse() + config.RouterConfigProperties.NetDb.Path = *netDbPath go signals.Handle() log.Info("parsing i2p router configuration")