mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-06-16 22:10:48 -04:00
resolve merge conflicts in lib/transport/noise
This commit is contained in:
27
README.md
27
README.md
@ -41,7 +41,7 @@ please keep up with these changes, as they will not be backward compatible and r
|
||||
- [ ] Elligator2
|
||||
- [ ] HKDF
|
||||
- [ ] HMAC
|
||||
- [ ] Noise subsystem
|
||||
- [/] Noise subsystem
|
||||
- End-to-End Crypto
|
||||
- [ ] Garlic messages
|
||||
- [ ] ElGamal/AES+SessionTag
|
||||
@ -50,9 +50,9 @@ please keep up with these changes, as they will not be backward compatible and r
|
||||
- [ ] Message parsing
|
||||
- [ ] Message handling
|
||||
- NetDB
|
||||
- [ ] Local storage
|
||||
- [ ] Persistence to disk
|
||||
- [ ] Reseeding
|
||||
- [/] Local storage
|
||||
- [/] Persistence to disk
|
||||
- [X] Reseeding
|
||||
- [ ] Lookups
|
||||
- [ ] Expiry
|
||||
- [ ] Exploration
|
||||
@ -60,12 +60,12 @@ please keep up with these changes, as they will not be backward compatible and r
|
||||
- [ ] Floodfill
|
||||
- [ ] LS2 and Encrypted Leasesets
|
||||
- Transports
|
||||
- [ ] Transport manager
|
||||
- [X] Transport manager
|
||||
- NTCP2
|
||||
- [ ] Handshake
|
||||
- [ ] Session tracking
|
||||
- [ ] Automatic session creation
|
||||
- SSU
|
||||
- SSU2
|
||||
- [ ] Handshake
|
||||
- [ ] Session tracking
|
||||
- [ ] Automatic session creation
|
||||
@ -78,7 +78,20 @@ please keep up with these changes, as they will not be backward compatible and r
|
||||
- [ ] Participating
|
||||
- [ ] Tunnel Message Crypto
|
||||
- [ ] Tunnel Message Fragmentation/Reassembly
|
||||
|
||||
- Common Data Structures
|
||||
- [X] Keys and Cert
|
||||
- [X] Key Certificates
|
||||
- [X] Certificate
|
||||
- [X] Lease
|
||||
- [X] Lease Set
|
||||
- [X] Router Info
|
||||
- [X] Router Identity
|
||||
- [X] Router Address
|
||||
- [X] Session Key
|
||||
- [X] Signature Types
|
||||
- [X] Destination
|
||||
- [X] Data Types
|
||||
- [X] Session Tag
|
||||
|
||||
## Contributing
|
||||
|
||||
|
12
go.mod
12
go.mod
@ -5,14 +5,26 @@ go 1.22
|
||||
toolchain go1.22.5
|
||||
|
||||
require (
|
||||
<<<<<<< HEAD
|
||||
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.9.0
|
||||
=======
|
||||
github.com/eyedeekay/go-unzip v0.0.0-20240201194209-560d8225b50e
|
||||
github.com/flynn/noise v1.1.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/stretchr/testify v1.9.0
|
||||
go.step.sm/crypto v0.51.2
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
golang.org/x/crypto v0.26.0
|
||||
)
|
||||
|
||||
require (
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
golang.org/x/sys v0.24.0 // indirect
|
||||
|
12
go.sum
12
go.sum
@ -1,8 +1,15 @@
|
||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
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=
|
||||
<<<<<<< HEAD
|
||||
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
|
||||
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
|
||||
=======
|
||||
github.com/eyedeekay/go-unzip v0.0.0-20240201194209-560d8225b50e h1:NMjWYVkgcQHGOy0/VxU0TU6smrcoxzj9hwDesx2sB0w=
|
||||
github.com/eyedeekay/go-unzip v0.0.0-20240201194209-560d8225b50e/go.mod h1:fKfFM3BsOOyjtZmEty7FsGzGabXo8Eb/dHjyIhTtxsE=
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
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=
|
||||
@ -18,6 +25,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
go.step.sm/crypto v0.51.2 h1:5EiCGIMg7IvQTGmJrwRosbXeprtT80OhoS/PJarg60o=
|
||||
go.step.sm/crypto v0.51.2/go.mod h1:QK7czLjN2k+uqVp5CHXxJbhc70kVRSP+0CQF3zsR5M0=
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
|
||||
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
|
||||
|
182
lib/netdb/doc.md
Normal file
182
lib/netdb/doc.md
Normal file
@ -0,0 +1,182 @@
|
||||
# netdb
|
||||
--
|
||||
import "github.com/go-i2p/go-i2p/lib/netdb"
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
const CacheFileName = "sizecache.txt"
|
||||
```
|
||||
name of file to hold precomputed size of netdb
|
||||
|
||||
#### type Entry
|
||||
|
||||
```go
|
||||
type Entry struct {
|
||||
*router_info.RouterInfo
|
||||
*lease_set.LeaseSet
|
||||
}
|
||||
```
|
||||
|
||||
netdb entry wraps a router info and provides serialization
|
||||
|
||||
#### func (*Entry) ReadFrom
|
||||
|
||||
```go
|
||||
func (e *Entry) ReadFrom(r io.Reader) (err error)
|
||||
```
|
||||
|
||||
#### func (*Entry) WriteTo
|
||||
|
||||
```go
|
||||
func (e *Entry) WriteTo(w io.Writer) (err error)
|
||||
```
|
||||
|
||||
#### type NetworkDatabase
|
||||
|
||||
```go
|
||||
type NetworkDatabase interface {
|
||||
// obtain a RouterInfo by its hash locally
|
||||
// return a RouterInfo if we found it locally
|
||||
// return nil if the RouterInfo cannot be found locally
|
||||
GetRouterInfo(hash common.Hash) router_info.RouterInfo
|
||||
|
||||
// store a router info locally
|
||||
StoreRouterInfo(ri router_info.RouterInfo)
|
||||
|
||||
// try obtaining more peers with a bootstrap instance until we get minRouters number of router infos
|
||||
// returns error if bootstrap.GetPeers returns an error otherwise returns nil
|
||||
Reseed(b bootstrap.Bootstrap, minRouters int) error
|
||||
|
||||
// return how many router infos we have
|
||||
Size() int
|
||||
|
||||
// Recaculate size of netdb from backend
|
||||
RecalculateSize() error
|
||||
|
||||
// ensure underlying resources exist , i.e. directories, files, configs
|
||||
Ensure() error
|
||||
}
|
||||
```
|
||||
|
||||
i2p network database, storage of i2p RouterInfos
|
||||
|
||||
#### type Resolver
|
||||
|
||||
```go
|
||||
type Resolver interface {
|
||||
// resolve a router info by hash
|
||||
// return a chan that yields the found RouterInfo or nil if it could not be found after timeout
|
||||
Lookup(hash common.Hash, timeout time.Duration) chan router_info.RouterInfo
|
||||
}
|
||||
```
|
||||
|
||||
resolves unknown RouterInfos given the hash of their RouterIdentity
|
||||
|
||||
#### func KademliaResolver
|
||||
|
||||
```go
|
||||
func KademliaResolver(netDb NetworkDatabase, pool *tunnel.Pool) (r Resolver)
|
||||
```
|
||||
create a new resolver that stores result into a NetworkDatabase and uses a
|
||||
tunnel pool for the lookup
|
||||
|
||||
#### type StdNetDB
|
||||
|
||||
```go
|
||||
type StdNetDB struct {
|
||||
DB string
|
||||
RouterInfos map[common.Hash]Entry
|
||||
LeaseSets map[common.Hash]Entry
|
||||
}
|
||||
```
|
||||
|
||||
standard network database implementation using local filesystem skiplist
|
||||
|
||||
#### func NewStdNetDB
|
||||
|
||||
```go
|
||||
func NewStdNetDB(db string) StdNetDB
|
||||
```
|
||||
|
||||
#### func (*StdNetDB) CheckFilePathValid
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) CheckFilePathValid(fpath string) bool
|
||||
```
|
||||
|
||||
#### func (*StdNetDB) Create
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Create() (err error)
|
||||
```
|
||||
create base network database directory
|
||||
|
||||
#### func (*StdNetDB) Ensure
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Ensure() (err error)
|
||||
```
|
||||
ensure that the network database exists
|
||||
|
||||
#### func (*StdNetDB) Exists
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Exists() bool
|
||||
```
|
||||
return true if the network db directory exists and is writable
|
||||
|
||||
#### func (*StdNetDB) GetRouterInfo
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) GetRouterInfo(hash common.Hash) (chnl chan router_info.RouterInfo)
|
||||
```
|
||||
|
||||
#### func (*StdNetDB) Path
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Path() string
|
||||
```
|
||||
get netdb path
|
||||
|
||||
#### func (*StdNetDB) RecalculateSize
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) RecalculateSize() (err error)
|
||||
```
|
||||
recalculateSize recalculates cached size of netdb
|
||||
|
||||
#### func (*StdNetDB) Reseed
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Reseed(b bootstrap.Bootstrap, minRouters int) (err error)
|
||||
```
|
||||
reseed if we have less than minRouters known routers returns error if reseed
|
||||
failed
|
||||
|
||||
#### func (*StdNetDB) Save
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Save() (err error)
|
||||
```
|
||||
|
||||
#### func (*StdNetDB) SaveEntry
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) SaveEntry(e *Entry) (err error)
|
||||
```
|
||||
|
||||
#### func (*StdNetDB) Size
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) Size() (routers int)
|
||||
```
|
||||
return how many routers we know about in our network database
|
||||
|
||||
#### func (*StdNetDB) SkiplistFile
|
||||
|
||||
```go
|
||||
func (db *StdNetDB) SkiplistFile(hash common.Hash) (fpath string)
|
||||
```
|
||||
get the skiplist file that a RouterInfo with this hash would go in
|
@ -3,13 +3,15 @@ package netdb
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/common/lease_set"
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
)
|
||||
|
||||
// netdb entry
|
||||
// wraps a router info and provides serialization
|
||||
type Entry struct {
|
||||
ri router_info.RouterInfo
|
||||
*router_info.RouterInfo
|
||||
*lease_set.LeaseSet
|
||||
}
|
||||
|
||||
func (e *Entry) WriteTo(w io.Writer) (err error) {
|
||||
|
27
lib/netdb/reseed/doc.md
Normal file
27
lib/netdb/reseed/doc.md
Normal file
@ -0,0 +1,27 @@
|
||||
# reseed
|
||||
--
|
||||
import "github.com/go-i2p/go-i2p/lib/netdb/reseed"
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
const (
|
||||
I2pUserAgent = "Wget/1.11.4"
|
||||
)
|
||||
```
|
||||
|
||||
#### type Reseed
|
||||
|
||||
```go
|
||||
type Reseed struct {
|
||||
net.Dialer
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### func (Reseed) SingleReseed
|
||||
|
||||
```go
|
||||
func (r Reseed) SingleReseed(uri string) ([]router_info.RouterInfo, error)
|
||||
```
|
94
lib/netdb/reseed/reseed.go
Normal file
94
lib/netdb/reseed/reseed.go
Normal file
@ -0,0 +1,94 @@
|
||||
package reseed
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/eyedeekay/go-unzip/pkg/unzip"
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
"github.com/go-i2p/go-i2p/lib/config"
|
||||
"github.com/go-i2p/go-i2p/lib/su3"
|
||||
)
|
||||
|
||||
const (
|
||||
I2pUserAgent = "Wget/1.11.4"
|
||||
)
|
||||
|
||||
type Reseed struct {
|
||||
net.Dialer
|
||||
}
|
||||
|
||||
func (r Reseed) SingleReseed(uri string) ([]router_info.RouterInfo, error) {
|
||||
transport := http.Transport{
|
||||
DialContext: r.DialContext,
|
||||
}
|
||||
client := http.Client{
|
||||
Transport: &transport,
|
||||
}
|
||||
URL, err := url.Parse(uri)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
header := http.Header{}
|
||||
header.Add("user-agent", "Wget/1.11.4")
|
||||
request := http.Request{
|
||||
URL: URL,
|
||||
Header: header,
|
||||
}
|
||||
response, err := client.Do(&request)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
su3file, err := su3.Read(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if su3file.FileType == su3.ZIP {
|
||||
if su3file.ContentType == su3.RESEED {
|
||||
if err == nil {
|
||||
content, err := io.ReadAll(su3file.Content(""))
|
||||
if err == nil {
|
||||
signature, err := io.ReadAll(su3file.Signature())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log.Println("warning: this doesn't validate the signature yet", signature)
|
||||
}
|
||||
zip := filepath.Join(config.RouterConfigProperties.NetDb.Path, "reseed.zip")
|
||||
err = os.WriteFile(zip, content, 0o644)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// content is a zip file, unzip it and get the files
|
||||
files, err := unzip.New().Extract(zip, config.RouterConfigProperties.NetDb.Path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(files) <= 0 {
|
||||
return nil, fmt.Errorf("error: reseed appears to have no content")
|
||||
}
|
||||
var ris []router_info.RouterInfo
|
||||
for _, f := range files {
|
||||
riB, err := os.ReadFile(f)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ri, _, err := router_info.ReadRouterInfo(riB)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ris = append(ris, ri)
|
||||
}
|
||||
err = os.Remove(zip)
|
||||
return ris, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("error: undefined reseed error")
|
||||
}
|
125
lib/netdb/std.go
125
lib/netdb/std.go
@ -11,6 +11,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/go-i2p/go-i2p/lib/bootstrap"
|
||||
"github.com/go-i2p/go-i2p/lib/common/base32"
|
||||
"github.com/go-i2p/go-i2p/lib/common/base64"
|
||||
common "github.com/go-i2p/go-i2p/lib/common/data"
|
||||
"github.com/go-i2p/go-i2p/lib/common/router_info"
|
||||
@ -19,43 +20,70 @@ import (
|
||||
)
|
||||
|
||||
// standard network database implementation using local filesystem skiplist
|
||||
type StdNetDB string
|
||||
type StdNetDB struct {
|
||||
DB string
|
||||
RouterInfos map[common.Hash]Entry
|
||||
LeaseSets map[common.Hash]Entry
|
||||
}
|
||||
|
||||
func (db StdNetDB) GetRouterInfo(hash common.Hash) (chnl chan router_info.RouterInfo) {
|
||||
func NewStdNetDB(db string) StdNetDB {
|
||||
return StdNetDB{
|
||||
DB: db,
|
||||
RouterInfos: make(map[common.Hash]Entry),
|
||||
LeaseSets: make(map[common.Hash]Entry),
|
||||
}
|
||||
}
|
||||
|
||||
func (db *StdNetDB) GetRouterInfo(hash common.Hash) (chnl chan router_info.RouterInfo) {
|
||||
if ri, ok := db.RouterInfos[hash]; ok {
|
||||
chnl <- *ri.RouterInfo
|
||||
return
|
||||
}
|
||||
fname := db.SkiplistFile(hash)
|
||||
f, err := os.Open(fname)
|
||||
if err != nil {
|
||||
buff := new(bytes.Buffer)
|
||||
if f, err := os.Open(fname); err != nil {
|
||||
return nil
|
||||
} else {
|
||||
if _, err := io.Copy(buff, f); err != nil {
|
||||
return nil
|
||||
}
|
||||
buff := new(bytes.Buffer)
|
||||
_, err = io.Copy(buff, f)
|
||||
f.Close()
|
||||
defer f.Close()
|
||||
}
|
||||
chnl = make(chan router_info.RouterInfo)
|
||||
ri, _, err := router_info.ReadRouterInfo(buff.Bytes())
|
||||
if err == nil {
|
||||
if _, ok := db.RouterInfos[hash]; !ok {
|
||||
db.RouterInfos[hash] = Entry{
|
||||
RouterInfo: &ri,
|
||||
}
|
||||
}
|
||||
chnl <- ri
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// get the skiplist file that a RouterInfo with this hash would go in
|
||||
func (db StdNetDB) SkiplistFile(hash common.Hash) (fpath string) {
|
||||
func (db *StdNetDB) SkiplistFile(hash common.Hash) (fpath string) {
|
||||
fname := base64.EncodeToString(hash[:])
|
||||
fpath = filepath.Join(db.Path(), fmt.Sprintf("r%c", fname[0]), fmt.Sprintf("routerInfo-%s.dat", fname))
|
||||
return
|
||||
}
|
||||
|
||||
// get netdb path
|
||||
func (db StdNetDB) Path() string {
|
||||
return string(db)
|
||||
func (db *StdNetDB) Path() string {
|
||||
return string(db.DB)
|
||||
}
|
||||
|
||||
// return how many routers we know about in our network database
|
||||
<<<<<<< HEAD
|
||||
func (db StdNetDB) Size() (routers int) {
|
||||
=======
|
||||
func (db *StdNetDB) Size() (routers int) {
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
// TODO: implement this
|
||||
var err error
|
||||
var data []byte
|
||||
if !util.CheckFileExists(db.cacheFilePath()) {
|
||||
if !util.CheckFileExists(db.cacheFilePath()) || util.CheckFileAge(db.cacheFilePath(), 2) || len(db.RouterInfos) == 0 {
|
||||
// regenerate
|
||||
err = db.RecalculateSize()
|
||||
if err != nil {
|
||||
@ -74,33 +102,67 @@ func (db StdNetDB) Size() (routers int) {
|
||||
const CacheFileName = "sizecache.txt"
|
||||
|
||||
// get filepath for storing netdb info cache
|
||||
func (db StdNetDB) cacheFilePath() string {
|
||||
func (db *StdNetDB) cacheFilePath() string {
|
||||
return filepath.Join(db.Path(), CacheFileName)
|
||||
}
|
||||
|
||||
func (db StdNetDB) CheckFilePathValid(fpath string) bool {
|
||||
func (db *StdNetDB) CheckFilePathValid(fpath string) bool {
|
||||
// TODO: make this better
|
||||
return strings.HasSuffix(fpath, ".dat")
|
||||
}
|
||||
|
||||
// recalculateSize recalculates cached size of netdb
|
||||
func (db StdNetDB) RecalculateSize() (err error) {
|
||||
fpath := db.cacheFilePath()
|
||||
func (db *StdNetDB) RecalculateSize() (err error) {
|
||||
count := 0
|
||||
err = filepath.Walk(fpath, func(fname string, info os.FileInfo, err error) error {
|
||||
err = filepath.Walk(db.Path(), func(fname string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
if !strings.HasPrefix(fname, db.Path()) {
|
||||
if db.Path() == fname {
|
||||
log.Info("path==name time to exit")
|
||||
return nil
|
||||
}
|
||||
log.Info("Outside of netDb dir time to exit", db.Path(), " ", fname)
|
||||
return err
|
||||
}
|
||||
return err
|
||||
}
|
||||
if db.CheckFilePathValid(fname) {
|
||||
// TODO: make sure it's in a skiplist directory
|
||||
log.Println("Reading in file:", fname)
|
||||
b, err := os.ReadFile(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ri, _, err := router_info.ReadRouterInfo(b)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
ih := ri.IdentHash().Bytes()
|
||||
log.Printf("Read in IdentHash: %s", base32.EncodeToString(ih[:]))
|
||||
for _, addr := range ri.RouterAddresses() {
|
||||
log.Println(string(addr.Bytes()))
|
||||
}
|
||||
if ent, ok := db.RouterInfos[ih]; !ok {
|
||||
db.RouterInfos[ri.IdentHash()] = Entry{
|
||||
RouterInfo: &ri,
|
||||
}
|
||||
} else {
|
||||
log.Println("entry previously found in table", ent, fname)
|
||||
}
|
||||
ri = router_info.RouterInfo{}
|
||||
count++
|
||||
} else {
|
||||
log.Println("Invalid path error")
|
||||
}
|
||||
return err
|
||||
})
|
||||
if err == nil {
|
||||
str := fmt.Sprintf("%d", count)
|
||||
var f *os.File
|
||||
<<<<<<< HEAD
|
||||
f, err = os.OpenFile(fpath, os.O_CREATE|os.O_WRONLY, 0o600)
|
||||
=======
|
||||
f, err = os.OpenFile(db.cacheFilePath(), os.O_CREATE|os.O_WRONLY, 0o600)
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
if err == nil {
|
||||
_, err = io.WriteString(f, str)
|
||||
f.Close()
|
||||
@ -110,7 +172,7 @@ func (db StdNetDB) RecalculateSize() (err error) {
|
||||
}
|
||||
|
||||
// return true if the network db directory exists and is writable
|
||||
func (db StdNetDB) Exists() bool {
|
||||
func (db *StdNetDB) Exists() bool {
|
||||
p := db.Path()
|
||||
// check root directory
|
||||
_, err := os.Stat(p)
|
||||
@ -125,10 +187,14 @@ func (db StdNetDB) Exists() bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func (db StdNetDB) SaveEntry(e *Entry) (err error) {
|
||||
func (db *StdNetDB) SaveEntry(e *Entry) (err error) {
|
||||
var f io.WriteCloser
|
||||
<<<<<<< HEAD
|
||||
var h common.Hash
|
||||
h = e.ri.IdentHash()
|
||||
=======
|
||||
h := e.RouterInfo.IdentHash()
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
// if err == nil {
|
||||
f, err = os.OpenFile(db.SkiplistFile(h), os.O_WRONLY|os.O_CREATE, 0o700)
|
||||
if err == nil {
|
||||
@ -142,14 +208,27 @@ func (db StdNetDB) SaveEntry(e *Entry) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (db *StdNetDB) Save() (err error) {
|
||||
for _, dbe := range db.RouterInfos {
|
||||
if e := db.SaveEntry(&dbe); e != nil {
|
||||
err = e
|
||||
// TODO: log this
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// 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) {
|
||||
func (db *StdNetDB) Reseed(b bootstrap.Bootstrap, minRouters int) (err error) {
|
||||
if db.Size() > minRouters {
|
||||
return nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ensure that the network database exists
|
||||
func (db StdNetDB) Ensure() (err error) {
|
||||
func (db *StdNetDB) Ensure() (err error) {
|
||||
if !db.Exists() {
|
||||
err = db.Create()
|
||||
}
|
||||
@ -157,7 +236,11 @@ func (db StdNetDB) Ensure() (err error) {
|
||||
}
|
||||
|
||||
// create base network database directory
|
||||
<<<<<<< HEAD
|
||||
func (db StdNetDB) Create() (err error) {
|
||||
=======
|
||||
func (db *StdNetDB) Create() (err error) {
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
mode := os.FileMode(0o700)
|
||||
p := db.Path()
|
||||
log.Infof("Create network database in %s", p)
|
||||
|
122
lib/transport/doc.md
Normal file
122
lib/transport/doc.md
Normal file
@ -0,0 +1,122 @@
|
||||
# transport
|
||||
--
|
||||
import "github.com/go-i2p/go-i2p/lib/transport"
|
||||
|
||||
*
|
||||
|
||||
i2np messages transports
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
var ErrNoTransportAvailable = errors.New("no transports available")
|
||||
```
|
||||
error for when we have no transports available to use
|
||||
|
||||
#### type Transport
|
||||
|
||||
```go
|
||||
type Transport interface {
|
||||
// Accept accepts an incoming session.
|
||||
Accept() (net.Conn, error)
|
||||
|
||||
// Addr returns an
|
||||
Addr() net.Addr
|
||||
|
||||
// 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
|
||||
SetIdentity(ident router_identity.RouterIdentity) error
|
||||
|
||||
// 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
|
||||
GetSession(routerInfo router_info.RouterInfo) (TransportSession, error)
|
||||
|
||||
// return true if a routerInfo is compatable with this transport
|
||||
Compatable(routerInfo router_info.RouterInfo) bool
|
||||
|
||||
// close the transport cleanly
|
||||
// blocks until done
|
||||
// returns an error if one happens
|
||||
Close() error
|
||||
|
||||
// get the name of this tranport as a string
|
||||
Name() string
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### type TransportMuxer
|
||||
|
||||
```go
|
||||
type TransportMuxer struct {
|
||||
}
|
||||
```
|
||||
|
||||
muxes multiple transports into 1 Transport implements transport.Transport
|
||||
|
||||
#### func Mux
|
||||
|
||||
```go
|
||||
func Mux(t ...Transport) (tmux *TransportMuxer)
|
||||
```
|
||||
mux a bunch of transports together
|
||||
|
||||
#### func (*TransportMuxer) Close
|
||||
|
||||
```go
|
||||
func (tmux *TransportMuxer) Close() (err error)
|
||||
```
|
||||
close every transport that this transport muxer has
|
||||
|
||||
#### func (*TransportMuxer) Compatable
|
||||
|
||||
```go
|
||||
func (tmux *TransportMuxer) Compatable(routerInfo router_info.RouterInfo) (compat bool)
|
||||
```
|
||||
is there a transport that we mux that is compatable with this router info?
|
||||
|
||||
#### func (*TransportMuxer) GetSession
|
||||
|
||||
```go
|
||||
func (tmux *TransportMuxer) GetSession(routerInfo router_info.RouterInfo) (s TransportSession, err error)
|
||||
```
|
||||
get a transport session given a router info return session and nil if successful
|
||||
return nil and ErrNoTransportAvailable if we failed to get a session
|
||||
|
||||
#### func (*TransportMuxer) Name
|
||||
|
||||
```go
|
||||
func (tmux *TransportMuxer) Name() string
|
||||
```
|
||||
the name of this transport with the names of all the ones that we mux
|
||||
|
||||
#### func (*TransportMuxer) SetIdentity
|
||||
|
||||
```go
|
||||
func (tmux *TransportMuxer) SetIdentity(ident router_identity.RouterIdentity) (err error)
|
||||
```
|
||||
set the identity for every transport
|
||||
|
||||
#### type TransportSession
|
||||
|
||||
```go
|
||||
type TransportSession interface {
|
||||
// queue an i2np message to be sent over the session
|
||||
// will block as long as the send queue is full
|
||||
// does not block if the queue is not full
|
||||
QueueSendI2NP(msg i2np.I2NPMessage)
|
||||
// return how many i2np messages are not completely sent yet
|
||||
SendQueueSize() int
|
||||
// blocking read the next fully recv'd i2np message from this session
|
||||
ReadNextI2NP() (i2np.I2NPMessage, error)
|
||||
// close the session cleanly
|
||||
// returns any errors that happen while closing the session
|
||||
Close() error
|
||||
}
|
||||
```
|
||||
|
||||
a session between 2 routers for tranmitting i2np messages securly
|
68
lib/transport/messages/doc.md
Normal file
68
lib/transport/messages/doc.md
Normal file
@ -0,0 +1,68 @@
|
||||
# ntcp
|
||||
--
|
||||
import "github.com/go-i2p/go-i2p/lib/transport/messages"
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
const (
|
||||
MessageTypeSessionRequest = 0x00
|
||||
MessageTypeSessionCreated = 0x01
|
||||
MessageTypeSessionConfirmed = 0x02
|
||||
MessageTypeData = 0x03
|
||||
)
|
||||
```
|
||||
|
||||
#### type Message
|
||||
|
||||
```go
|
||||
type Message interface {
|
||||
// Type returns the message type
|
||||
Type() MessageType
|
||||
// Payload returns the message payload
|
||||
Payload() []byte
|
||||
// PayloadSize returns the message payload size
|
||||
PayloadSize() int
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### type MessageType
|
||||
|
||||
```go
|
||||
type MessageType uint8
|
||||
```
|
||||
|
||||
|
||||
#### type SessionRequest
|
||||
|
||||
```go
|
||||
type SessionRequest struct {
|
||||
XContent []byte // 32-byte X value
|
||||
|
||||
Padding []byte // padding of message 1
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### func (*SessionRequest) Payload
|
||||
|
||||
```go
|
||||
func (sr *SessionRequest) Payload() []byte
|
||||
```
|
||||
Payload returns the message payload
|
||||
|
||||
#### func (*SessionRequest) PayloadSize
|
||||
|
||||
```go
|
||||
func (sr *SessionRequest) PayloadSize() int
|
||||
```
|
||||
PayloadSize returns the message payload size
|
||||
|
||||
#### func (*SessionRequest) Type
|
||||
|
||||
```go
|
||||
func (sr *SessionRequest) Type() MessageType
|
||||
```
|
||||
Type returns the message type
|
30
lib/transport/ntcp/doc.md
Normal file
30
lib/transport/ntcp/doc.md
Normal file
@ -0,0 +1,30 @@
|
||||
# ntcp
|
||||
--
|
||||
import "github.com/go-i2p/go-i2p/lib/transport/ntcp"
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
const (
|
||||
NTCP_PROTOCOL_VERSION = 2
|
||||
NTCP_PROTOCOL_NAME = "NTCP2"
|
||||
NTCP_MESSAGE_MAX_SIZE = 65537
|
||||
)
|
||||
```
|
||||
|
||||
#### type Session
|
||||
|
||||
```go
|
||||
type Session struct{}
|
||||
```
|
||||
|
||||
Session implements TransportSession An established transport session
|
||||
|
||||
#### type Transport
|
||||
|
||||
```go
|
||||
type Transport struct{}
|
||||
```
|
||||
|
||||
Transport is an ntcp transport implementing transport.Transport interface
|
@ -4,4 +4,8 @@ import "github.com/go-i2p/go-i2p/lib/transport/noise"
|
||||
|
||||
// Session implements TransportSession
|
||||
// An established transport session
|
||||
<<<<<<< HEAD
|
||||
type Session noise.NoiseSession
|
||||
=======
|
||||
type Session struct{}
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
|
@ -12,5 +12,10 @@ const (
|
||||
NTCP_MESSAGE_MAX_SIZE = 65537
|
||||
)
|
||||
|
||||
<<<<<<< HEAD
|
||||
// NTCPTransport is an ntcp transport implementing transport.Transport interface
|
||||
type NTCPTransport noise.NoiseTransport
|
||||
=======
|
||||
// Transport is an ntcp transport implementing transport.Transport interface
|
||||
type Transport struct{}
|
||||
>>>>>>> 9f4154ff457f962bc3b5d77e266b5d87b4de3742
|
||||
|
7
lib/transport/ssu/doc.md
Normal file
7
lib/transport/ssu/doc.md
Normal file
@ -0,0 +1,7 @@
|
||||
# ssu
|
||||
--
|
||||
import "github.com/go-i2p/go-i2p/lib/transport/ssu"
|
||||
|
||||
i2p ssu transport implementation
|
||||
|
||||
## Usage
|
8
main.go
8
main.go
@ -1,15 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
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")
|
||||
|
||||
log.Info("using netDb in:", config.RouterConfigProperties.NetDb.Path)
|
||||
log.Info("starting up i2p router")
|
||||
r, err := router.CreateRouter()
|
||||
if err == nil {
|
||||
|
Reference in New Issue
Block a user