mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 21:55:18 -04:00
make it compile
This commit is contained in:
@ -1,11 +0,0 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/stdi2p"
|
||||
)
|
||||
|
||||
type Reseed interface {
|
||||
// do reseed, return nil on success otherwise error
|
||||
// sends down all retrieved SU3 files down chan
|
||||
Reseed(chnl chan *stdi2p.SU3) error
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
package bootstrap
|
||||
|
||||
import (
|
||||
"github.com/bounce-chat/go-i2p/lib/stdi2p"
|
||||
)
|
||||
|
||||
|
||||
type HTTPSReseed string
|
||||
|
||||
func (r HTTPSReseed) Reseed(chnl chan *stdi2p.SU3) (err error) {
|
||||
return
|
||||
}
|
14
lib/netdb/bootstrap.go
Normal file
14
lib/netdb/bootstrap.go
Normal file
@ -0,0 +1,14 @@
|
||||
package netdb
|
||||
|
||||
type Reseed interface {
|
||||
// do reseed, return nil on success otherwise error
|
||||
// sends down all Netdb entries down chan
|
||||
// closes channel when done
|
||||
Reseed(chnl chan *Entry) error
|
||||
}
|
||||
|
||||
|
||||
func GetRandomReseed() Reseed {
|
||||
// TODO: hardcoded value
|
||||
return HTTPSReseed("https://i2p.rocks:445/")
|
||||
}
|
@ -1 +1,18 @@
|
||||
package netdb
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Entry struct {
|
||||
fname string
|
||||
}
|
||||
|
||||
func (e *Entry) FilePath(n StdNetDB) (str string) {
|
||||
return filepath.Join(string(n), e.fname)
|
||||
}
|
||||
|
||||
func (e *Entry) WriteTo(w io.Writer) (err error) {
|
||||
return
|
||||
}
|
||||
|
8
lib/netdb/reseed.go
Normal file
8
lib/netdb/reseed.go
Normal file
@ -0,0 +1,8 @@
|
||||
package netdb
|
||||
|
||||
type HTTPSReseed string
|
||||
|
||||
func (r HTTPSReseed) Reseed(chnl chan *Entry) (err error) {
|
||||
close(chnl)
|
||||
return
|
||||
}
|
@ -1,10 +1,10 @@
|
||||
package netdb
|
||||
|
||||
import (
|
||||
"github.com/golang/glog"
|
||||
"github.com/majestrate/goi2p/lib/common"
|
||||
log "github.com/golang/glog"
|
||||
"github.com/bounce-chat/go-i2p/lib/common"
|
||||
"io"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
// standard network database implementation
|
||||
@ -28,9 +28,67 @@ func (db StdNetDB) Exists() bool {
|
||||
return common.FileExists(db.Path())
|
||||
}
|
||||
|
||||
func (db StdNetDB) SaveEntry(e *Entry) (err error) {
|
||||
var f io.WriteCloser
|
||||
f, err = os.OpenFile(e.FilePath(db), os.O_WRONLY, 0600)
|
||||
if err == nil {
|
||||
err = e.WriteTo(f)
|
||||
if err != nil {
|
||||
log.Errorf("failed to write netdb entry: %s", err.Error())
|
||||
}
|
||||
f.Close()
|
||||
} else {
|
||||
log.Errorf("failed to save netdb entry: %s", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
// reseed if we have less than minRouters known routers
|
||||
// returns error if reseed failed
|
||||
func (db StdNetDB) Reseed(minRouters int) (err error) {
|
||||
current := db.KnownPeerCount()
|
||||
if current <= minRouters {
|
||||
// we need to reseed
|
||||
rs := GetRandomReseed()
|
||||
log.Infof("Reseeding from %s", rs)
|
||||
chnl := make(chan *Entry)
|
||||
// receive entries from reseed
|
||||
go func(c chan *Entry) {
|
||||
count := 0
|
||||
for {
|
||||
e, ok := <- c
|
||||
if ok {
|
||||
// got an entry
|
||||
// save it to our netdb
|
||||
err := db.SaveEntry(e)
|
||||
if err == nil {
|
||||
count ++
|
||||
}
|
||||
}
|
||||
}
|
||||
}(chnl) // call
|
||||
err = rs.Reseed(chnl)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ensure that the network database exists and is seeded with a minimum number of routers
|
||||
func (db StdNetDB) Ensure(minRouters int) (err error) {
|
||||
if ! db.Exists() {
|
||||
err = db.Create()
|
||||
}
|
||||
if err == nil {
|
||||
// database directory ensured
|
||||
// try to reseed
|
||||
err = db.Reseed(minRouters)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// create base network database directory
|
||||
func (db StdNetDB) Create() (err error) {
|
||||
glog.Infof("Create network database in %s", db.Path())
|
||||
log.Infof("Create network database in %s", db.Path())
|
||||
err = os.Mkdir(db.Path(), 0600)
|
||||
return
|
||||
}
|
||||
|
@ -23,5 +23,9 @@ func CreateRouter() (r *Router, err error) {
|
||||
|
||||
// run i2p router mainloop
|
||||
func (r *Router) Run() {
|
||||
r.ndb.Run()
|
||||
// make sure the netdb is ready
|
||||
err := r.ndb.Ensure(r.cfg.Bootstrap.LowPeerThreshold)
|
||||
if err == nil {
|
||||
// netdb ready
|
||||
}
|
||||
}
|
||||
|
8
main.go
8
main.go
@ -4,7 +4,7 @@ import (
|
||||
|
||||
"github.com/bounce-chat/go-i2p/lib/router"
|
||||
|
||||
"github.com/golang/glog"
|
||||
log "github.com/golang/glog"
|
||||
"flag"
|
||||
)
|
||||
|
||||
@ -14,13 +14,13 @@ func main() {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
glog.Info("parsing i2p router configuration")
|
||||
log.Info("parsing i2p router configuration")
|
||||
|
||||
glog.Info("starting up i2p router")
|
||||
log.Info("starting up i2p router")
|
||||
r, err := router.CreateRouter()
|
||||
if err == nil {
|
||||
r.Run()
|
||||
} else {
|
||||
glog.Errorf("failed to create i2p router: %s", err)
|
||||
log.Errorf("failed to create i2p router: %s", err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user