From 67d49585afa6c14172ca7f6b63a0a5ad546c3325 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Thu, 28 Jan 2016 10:16:26 -0500 Subject: [PATCH] add base files --- .gitignore | 3 + lib/bootstrap/bootstrap.go | 11 +++ lib/bootstrap/reseed.go | 12 +++ lib/common/base32/base32.go | 11 +++ lib/common/base64/base64.go | 11 +++ lib/common/data.go | 5 + lib/common/utils.go | 14 +++ lib/config/bootstrap.go | 6 ++ lib/config/router.go | 13 +++ lib/crypto/aes.go | 28 ++++++ lib/crypto/dsa.go | 71 +++++++++++++++ lib/crypto/dsa_test.go | 28 ++++++ lib/crypto/elg.go | 172 +++++++++++++++++++++++++++++++++++ lib/crypto/elg_test.go | 50 ++++++++++ lib/crypto/hmac.go | 43 +++++++++ lib/crypto/hmac_test.go | 28 ++++++ lib/netdb/doc.go | 5 + lib/netdb/entry.go | 1 + lib/netdb/std.go | 36 ++++++++ lib/router/router.go | 27 ++++++ lib/ssu/doc.go | 7 ++ lib/ssu/packet.go | 1 + lib/ssu/session.go | 3 + lib/stdi2p/RouterIdentity.go | 7 ++ lib/stdi2p/RouterInfo.go | 6 ++ lib/stdi2p/i2np.go | 2 + lib/stdi2p/su3.go | 7 ++ main.go | 26 ++++++ 28 files changed, 634 insertions(+) create mode 100644 .gitignore create mode 100644 lib/bootstrap/bootstrap.go create mode 100644 lib/bootstrap/reseed.go create mode 100644 lib/common/base32/base32.go create mode 100644 lib/common/base64/base64.go create mode 100644 lib/common/data.go create mode 100644 lib/common/utils.go create mode 100644 lib/config/bootstrap.go create mode 100644 lib/config/router.go create mode 100644 lib/crypto/aes.go create mode 100644 lib/crypto/dsa.go create mode 100644 lib/crypto/dsa_test.go create mode 100644 lib/crypto/elg.go create mode 100644 lib/crypto/elg_test.go create mode 100644 lib/crypto/hmac.go create mode 100644 lib/crypto/hmac_test.go create mode 100644 lib/netdb/doc.go create mode 100644 lib/netdb/entry.go create mode 100644 lib/netdb/std.go create mode 100644 lib/router/router.go create mode 100644 lib/ssu/doc.go create mode 100644 lib/ssu/packet.go create mode 100644 lib/ssu/session.go create mode 100644 lib/stdi2p/RouterIdentity.go create mode 100644 lib/stdi2p/RouterInfo.go create mode 100644 lib/stdi2p/i2np.go create mode 100644 lib/stdi2p/su3.go create mode 100644 main.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..298d9cf --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +\#* +.\#* \ No newline at end of file diff --git a/lib/bootstrap/bootstrap.go b/lib/bootstrap/bootstrap.go new file mode 100644 index 0000000..dbe9233 --- /dev/null +++ b/lib/bootstrap/bootstrap.go @@ -0,0 +1,11 @@ +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 +} diff --git a/lib/bootstrap/reseed.go b/lib/bootstrap/reseed.go new file mode 100644 index 0000000..ad108b5 --- /dev/null +++ b/lib/bootstrap/reseed.go @@ -0,0 +1,12 @@ +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 +} diff --git a/lib/common/base32/base32.go b/lib/common/base32/base32.go new file mode 100644 index 0000000..d141cfe --- /dev/null +++ b/lib/common/base32/base32.go @@ -0,0 +1,11 @@ +// +// base32 encoding using i2p's alphabet +// +package base32 + +import ( + b32 "encoding/base32" +) + +// i2p base32 encoding +var I2PEncoding *b32.Encoding = b32.NewEncoding("abcdefghijklmnopqrstuvwxyz234567") diff --git a/lib/common/base64/base64.go b/lib/common/base64/base64.go new file mode 100644 index 0000000..ad2c02d --- /dev/null +++ b/lib/common/base64/base64.go @@ -0,0 +1,11 @@ +// +// base64 encoding with i2p's alphabet +// +package base64 + +import ( + b64 "encoding/base64" +) + +// i2p base64 encoding +var I2PEncoding *b64.Encoding = b64.NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-~") diff --git a/lib/common/data.go b/lib/common/data.go new file mode 100644 index 0000000..845bfd5 --- /dev/null +++ b/lib/common/data.go @@ -0,0 +1,5 @@ +package common + + +// the sha256 of some datastructure +type IdentHash [32]byte diff --git a/lib/common/utils.go b/lib/common/utils.go new file mode 100644 index 0000000..2fe10d8 --- /dev/null +++ b/lib/common/utils.go @@ -0,0 +1,14 @@ +package common + +import ( + "os" +) + +// check if a file is there and writeable +func FileExists(fname string) (exists bool) { + _, err := os.Stat(fname) + if err == nil { + exists = true + } + return +} diff --git a/lib/config/bootstrap.go b/lib/config/bootstrap.go new file mode 100644 index 0000000..5b2d72a --- /dev/null +++ b/lib/config/bootstrap.go @@ -0,0 +1,6 @@ +package config + + +type BootstrapConfig struct { + LowPeerThreshold int +} diff --git a/lib/config/router.go b/lib/config/router.go new file mode 100644 index 0000000..751e5b6 --- /dev/null +++ b/lib/config/router.go @@ -0,0 +1,13 @@ +package config + +// router.config options +type RouterConfig struct { + NetDbDir string + + Bootstrap BootstrapConfig +} + +// defaults for router +var Router = &RouterConfig{ + NetDbDir: "./netDb", +} diff --git a/lib/crypto/aes.go b/lib/crypto/aes.go new file mode 100644 index 0000000..d3f7def --- /dev/null +++ b/lib/crypto/aes.go @@ -0,0 +1,28 @@ +package crypto + +type AesCBC struct { +} + +type AesECB struct { +} + + +type TunnelKey [32]byte +type TunnelIV [16]byte + +// +// tunnel aes base +// +type TunnelAes struct { + layerKey TunnelKey + ivKey TunnelKey + iv TunnelIV +} + +type TunnelEncryption struct { + TunnelAes +} + +type TunnelDecryption struct { + TunnelAes +} diff --git a/lib/crypto/dsa.go b/lib/crypto/dsa.go new file mode 100644 index 0000000..c4a1a28 --- /dev/null +++ b/lib/crypto/dsa.go @@ -0,0 +1,71 @@ +package crypto + +import ( + "crypto/dsa" + "io" + "math/big" +) + +var dsap = new(big.Int).SetBytes([]byte{ + 0x9c, 0x05, 0xb2, 0xaa, 0x96, 0x0d, 0x9b, 0x97, 0xb8, 0x93, 0x19, 0x63, 0xc9, 0xcc, 0x9e, 0x8c, + 0x30, 0x26, 0xe9, 0xb8, 0xed, 0x92, 0xfa, 0xd0, 0xa6, 0x9c, 0xc8, 0x86, 0xd5, 0xbf, 0x80, 0x15, + 0xfc, 0xad, 0xae, 0x31, 0xa0, 0xad, 0x18, 0xfa, 0xb3, 0xf0, 0x1b, 0x00, 0xa3, 0x58, 0xde, 0x23, + 0x76, 0x55, 0xc4, 0x96, 0x4a, 0xfa, 0xa2, 0xb3, 0x37, 0xe9, 0x6a, 0xd3, 0x16, 0xb9, 0xfb, 0x1c, + 0xc5, 0x64, 0xb5, 0xae, 0xc5, 0xb6, 0x9a, 0x9f, 0xf6, 0xc3, 0xe4, 0x54, 0x87, 0x07, 0xfe, 0xf8, + 0x50, 0x3d, 0x91, 0xdd, 0x86, 0x02, 0xe8, 0x67, 0xe6, 0xd3, 0x5d, 0x22, 0x35, 0xc1, 0x86, 0x9c, + 0xe2, 0x47, 0x9c, 0x3b, 0x9d, 0x54, 0x01, 0xde, 0x04, 0xe0, 0x72, 0x7f, 0xb3, 0x3d, 0x65, 0x11, + 0x28, 0x5d, 0x4c, 0xf2, 0x95, 0x38, 0xd9, 0xe3, 0xb6, 0x05, 0x1f, 0x5b, 0x22, 0xcc, 0x1c, 0x93, +}) + +var dsaq = new(big.Int).SetBytes([]byte{ + 0xa5, 0xdf, 0xc2, 0x8f, 0xef, 0x4c, 0xa1, 0xe2, 0x86, 0x74, 0x4c, 0xd8, 0xee, 0xd9, 0xd2, 0x9d, + 0x68, 0x40, 0x46, 0xb7, +}); + +var dsag = new(big.Int).SetBytes([]byte{ + 0x0c, 0x1f, 0x4d, 0x27, 0xd4, 0x00, 0x93, 0xb4, 0x29, 0xe9, 0x62, 0xd7, 0x22, 0x38, 0x24, 0xe0, + 0xbb, 0xc4, 0x7e, 0x7c, 0x83, 0x2a, 0x39, 0x23, 0x6f, 0xc6, 0x83, 0xaf, 0x84, 0x88, 0x95, 0x81, + 0x07, 0x5f, 0xf9, 0x08, 0x2e, 0xd3, 0x23, 0x53, 0xd4, 0x37, 0x4d, 0x73, 0x01, 0xcd, 0xa1, 0xd2, + 0x3c, 0x43, 0x1f, 0x46, 0x98, 0x59, 0x9d, 0xda, 0x02, 0x45, 0x18, 0x24, 0xff, 0x36, 0x97, 0x52, + 0x59, 0x36, 0x47, 0xcc, 0x3d, 0xdc, 0x19, 0x7d, 0xe9, 0x85, 0xe4, 0x3d, 0x13, 0x6c, 0xdc, 0xfc, + 0x6b, 0xd5, 0x40, 0x9c, 0xd2, 0xf4, 0x50, 0x82, 0x11, 0x42, 0xa5, 0xe6, 0xf8, 0xeb, 0x1c, 0x3a, + 0xb5, 0xd0, 0x48, 0x4b, 0x81, 0x29, 0xfc, 0xf1, 0x7b, 0xce, 0x4f, 0x7f, 0x33, 0x32, 0x1c, 0x3c, + 0xb3, 0xdb, 0xb1, 0x4a, 0x90, 0x5e, 0x7b, 0x2b, 0x3e, 0x93, 0xbe, 0x47, 0x08, 0xcb, 0xcc, 0x82, +}); + +var param = dsa.Parameters{ + P: dsap, + Q: dsaq, + G: dsag, +} + +// generate a dsa keypair +func DSAGenerate(priv *dsa.PrivateKey, rand io.Reader) error { + // put our paramters in + priv.P = param.P + priv.Q = param.Q + priv.G = param.G + // generate the keypair + return dsa.GenerateKey(priv, rand) +} + +// create i2p dsa public key given its public component +func DSAPublicKey(Y *big.Int) *dsa.PublicKey { + return &dsa.PublicKey{ + Parameters: param, + Y: Y, + } +} + +// createa i2p dsa private key given its public component +func DSAPrivkey(X *big.Int) *dsa.PrivateKey { + Y := new(big.Int) + Y.Exp(dsag, X, dsap) + return &dsa.PrivateKey{ + PublicKey: dsa.PublicKey{ + Parameters: param, + Y: Y, + }, + X: X, + } +} diff --git a/lib/crypto/dsa_test.go b/lib/crypto/dsa_test.go new file mode 100644 index 0000000..a38d70f --- /dev/null +++ b/lib/crypto/dsa_test.go @@ -0,0 +1,28 @@ +package crypto + +import ( + "crypto/dsa" + "crypto/rand" + "testing" +) + + +func TestDSA(t *testing.T) { + rng := rand.Reader + kp := new(dsa.PrivateKey) + err := DSAGenerate(kp, rng) + if err == nil { + t.Logf("DSA Key Pair generated") + } else { + t.Logf("error while generating key: %s", err) + t.Fail() + } + h := make([]byte, 20) + _, _, err = dsa.Sign(rng, kp, h) + if err == nil { + t.Log("signed") + } else { + t.Logf("error signing: %s", err) + t.Fail() + } +} diff --git a/lib/crypto/elg.go b/lib/crypto/elg.go new file mode 100644 index 0000000..8c447ce --- /dev/null +++ b/lib/crypto/elg.go @@ -0,0 +1,172 @@ +package crypto + +import ( + "crypto/sha256" + "crypto/subtle" + "errors" + "golang.org/x/crypto/openpgp/elgamal" + "io" + "math/big" +) + +var elgp = new(big.Int).SetBytes([]byte{ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34, + 0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1, 0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74, + 0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22, 0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD, + 0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B, 0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37, + 0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45, 0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6, + 0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B, 0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED, + 0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5, 0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6, + 0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D, 0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05, + 0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A, 0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F, + 0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96, 0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB, + 0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D, 0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04, + 0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x18, 0x21, 0x7C, 0x32, 0x90, 0x5E, 0x46, 0x2E, 0x36, 0xCE, 0x3B, + 0xE3, 0x9E, 0x77, 0x2C, 0x18, 0x0E, 0x86, 0x03, 0x9B, 0x27, 0x83, 0xA2, 0xEC, 0x07, 0xA2, 0x8F, + 0xB5, 0xC5, 0x5D, 0xF0, 0x6F, 0x4C, 0x52, 0xC9, 0xDE, 0x2B, 0xCB, 0xF6, 0x95, 0x58, 0x17, 0x18, + 0x39, 0x95, 0x49, 0x7C, 0xEA, 0x95, 0x6A, 0xE5, 0x15, 0xD2, 0x26, 0x18, 0x98, 0xFA, 0x05, 0x10, + 0x15, 0x72, 0x8E, 0x5A, 0x8A, 0xAC, 0xAA, 0x68, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, +}) + +var one = big.NewInt(1) +var elgg = big.NewInt(2) + +var ElgDecryptFail = errors.New("failed to decrypt elgamal encrypted data") +var ElgEncryptTooBig = errors.New("failed to encrypt data, too big for elgamal") + +// generate an elgamal key pair +func ElgamalGenerate(priv *elgamal.PrivateKey, rand io.Reader) (err error) { + priv.P = elgp + priv.G = elgg + xBytes := make([]byte, priv.P.BitLen()/8) + _, err = io.ReadFull(rand, xBytes) + if err == nil { + // set private key + priv.X = new(big.Int).SetBytes(xBytes) + // compute public key + priv.Y = new(big.Int).Exp(priv.G, priv.X, priv.P) + } + return +} + +// decrypt an elgamal encrypted message, i2p style +func ElgamelDecrypt(priv *elgamal.PrivateKey, data []byte, zeroPadding bool) (decrypted []byte, err error) { + a := new(big.Int) + b := new(big.Int) + idx := 0 + if zeroPadding { + idx ++ + } + a.SetBytes(data[idx : idx + 256]) + if zeroPadding { + idx ++ + } + b.SetBytes(data[idx + 256:]) + + // decrypt + m := new(big.Int).Mod(new(big.Int).Mul(b, new(big.Int).Exp(a,new(big.Int).Sub(new(big.Int).Sub(priv.P, priv.X), one), priv.P)), priv.P).Bytes() + + // check digest + d := sha256.Sum256(m[33:255]) + good := 0 + if subtle.ConstantTimeCompare(d[:], m[1:33]) == 1 { + // decryption successful + good = 1 + } else { + // decrypt failed + err = ElgDecryptFail + } + // copy result + decrypted = make([]byte, 222) + subtle.ConstantTimeCopy(good, decrypted, m[33:255]) + + if good == 0 { + // if decrypt failed nil out decrypted slice + decrypted = nil + } + return +} + + +type ElgamalEncryption struct { + p, a, b1 *big.Int +} + + +func (elg *ElgamalEncryption) Encrypt(data []byte, zeroPadding bool) (encrypted []byte, err error) { + if len(data) > 222 { + err = ElgEncryptTooBig + return + } + mbytes := make([]byte, 255) + mbytes[0] = 0xFF + copy(mbytes[33:], data) + // do sha256 of payload + d := sha256.Sum256(mbytes[33:len(data)+33]) + copy(mbytes[1:], d[:]) + m := new(big.Int).SetBytes(mbytes) + // do encryption + b := new(big.Int).Mod(new(big.Int).Mul(elg.b1, m), elg.p).Bytes() + + if zeroPadding { + encrypted = make([]byte, 514) + copy(encrypted[1:], elg.a.Bytes()) + copy(encrypted[258:], b) + } else { + encrypted = make([]byte, 512) + copy(encrypted, elg.a.Bytes()) + copy(encrypted[256:], b) + } + return +} + +// create an elgamal public key from byte slice +func ElgamalPublicKey(data []byte) (k *elgamal.PublicKey) { + if len(data) == 256 { + k = &elgamal.PublicKey{ + G: elgg, + P: elgp, + Y: new(big.Int).SetBytes(data), + } + } + return +} + +// create an elgamal private key from byte slice +func ElgamalPrivateKey(data []byte) (k *elgamal.PrivateKey) { + if len(data) == 256 { + x := new(big.Int).SetBytes(data) + y := new(big.Int).Exp(elgg, x, elgp) + k = &elgamal.PrivateKey{ + PublicKey: elgamal.PublicKey{ + Y: y, + G: elgg, + P: elgp, + }, + X: x, + } + } + return +} + +// create a new elgamal encryption session +func NewElgamalEncryption(pub *elgamal.PublicKey, rand io.Reader) (enc *ElgamalEncryption, err error) { + kbytes := make([]byte, 256) + k := new(big.Int) + for err == nil { + _, err = io.ReadFull(rand, kbytes) + k = new(big.Int).SetBytes(kbytes) + k = k.Mod(k, pub.P) + if k.Sign() != 0 { + break + } + } + if err == nil { + enc = &ElgamalEncryption{ + p: pub.P, + a: new(big.Int).Exp(pub.G, k, pub.P), + b1: new(big.Int).Exp(pub.Y, k, pub.P), + } + } + return +} diff --git a/lib/crypto/elg_test.go b/lib/crypto/elg_test.go new file mode 100644 index 0000000..2544e94 --- /dev/null +++ b/lib/crypto/elg_test.go @@ -0,0 +1,50 @@ +package crypto + +import ( + "bytes" + "crypto/rand" + "golang.org/x/crypto/openpgp/elgamal" + "io" + "testing" +) + + +func TestElg(t *testing.T) { + k := new(elgamal.PrivateKey) + err := ElgamalGenerate(k, rand.Reader) + if err == nil { + msg := make([]byte, 222) + _, err := io.ReadFull(rand.Reader, msg) + if err == nil { + pub := ElgamalPublicKey(k.Y.Bytes()) + enc, err := NewElgamalEncryption(pub, rand.Reader) + if err == nil { + emsg, err := enc.Encrypt(msg, true) + if err == nil { + dec, err := ElgamelDecrypt(k, emsg, true) + if err == nil { + if ! bytes.Equal(dec, msg) { + t.Logf("%q != %q", dec, msg) + t.Fail() + } + } else { + t.Logf("decrypt failed: %s", err.Error()) + t.Fail() + } + } else { + t.Logf("failed to encrypt message: %s", err.Error()) + t.Fail() + } + } else { + t.Logf("failed to create encryption: %s", err.Error()) + t.Fail() + } + } else { + t.Logf("failed to generate random message: %s", err.Error()) + t.Fail() + } + } else { + t.Logf("error while generating key: %s", err.Error()) + t.Fail() + } +} diff --git a/lib/crypto/hmac.go b/lib/crypto/hmac.go new file mode 100644 index 0000000..3204add --- /dev/null +++ b/lib/crypto/hmac.go @@ -0,0 +1,43 @@ +package crypto + +import ( + "crypto/md5" +) + +const IPAD = byte(0x36) +const OPAD = byte(0x5C) + +type HMACKey [32]byte +type HMACDigest [16]byte + +func (hk HMACKey) xor(p byte) (i []byte) { + i = make([]byte, 64) + for idx, b := range hk { + i[idx] = b ^ p + } + c := 32 + for c > 0 { + c-- + i[c+32] = p + } + return +} + +// +// do i2p hmac +// +func I2PHMAC(data []byte, k HMACKey) (d HMACDigest) { + + buff := make([]byte, 64+len(data)) + ip := k.xor(IPAD) + copy(buff, ip) + copy(buff[64:], data) + h := md5.Sum(buff) + + buff = make([]byte, 96) + copy(buff, k.xor(OPAD)) + copy(buff[64:], h[:]) + // go zeros slices so we do not have to zero + d = md5.Sum(buff) + return +} diff --git a/lib/crypto/hmac_test.go b/lib/crypto/hmac_test.go new file mode 100644 index 0000000..b72b326 --- /dev/null +++ b/lib/crypto/hmac_test.go @@ -0,0 +1,28 @@ +package crypto + +import ( + "bytes" + "encoding/base64" + "testing" +) + + +// XXX: IMPLEMENT THIS +func Test_I2PHMAC(t *testing.T) { + data := make([]byte, 64) + for idx, _ := range data { + data[idx] = 1 + } + var k HMACKey + for idx, _ := range k[:] { + k[idx] = 1 + } + d := I2PHMAC(data, k) + expected_str := "WypV9tIaH1Kn9i7/9OqP6Q==" + expected, _ := base64.StdEncoding.DecodeString(expected_str) + if ! bytes.Equal(d[:], expected) { + t.Logf("%d vs %d", len(d), len(expected)) + t.Logf("%q != %q", d, expected) + t.Fail() + } +} diff --git a/lib/netdb/doc.go b/lib/netdb/doc.go new file mode 100644 index 0000000..2d97085 --- /dev/null +++ b/lib/netdb/doc.go @@ -0,0 +1,5 @@ +// +// +// +// +package netdb diff --git a/lib/netdb/entry.go b/lib/netdb/entry.go new file mode 100644 index 0000000..7850708 --- /dev/null +++ b/lib/netdb/entry.go @@ -0,0 +1 @@ +package netdb diff --git a/lib/netdb/std.go b/lib/netdb/std.go new file mode 100644 index 0000000..aa31ff2 --- /dev/null +++ b/lib/netdb/std.go @@ -0,0 +1,36 @@ +package netdb + +import ( + "github.com/golang/glog" + "github.com/majestrate/goi2p/lib/common" + "os" + "time" +) + +// standard network database implementation +type StdNetDB string + + +// get netdb path +func (db StdNetDB) Path() string { + return string(db) +} + +// +// return how many routers we know about in our network database +// +func (db StdNetDB) KnownPeerCount() (routers int) { + return +} + +// return true if the network db directory exists and is writable +func (db StdNetDB) Exists() bool { + return common.FileExists(db.Path()) +} + +// create base network database directory +func (db StdNetDB) Create() (err error) { + glog.Infof("Create network database in %s", db.Path()) + err = os.Mkdir(db.Path(), 0600) + return +} diff --git a/lib/router/router.go b/lib/router/router.go new file mode 100644 index 0000000..fb9c6c4 --- /dev/null +++ b/lib/router/router.go @@ -0,0 +1,27 @@ +package router + +import ( + "github.com/bounce-chat/go-i2p/lib/config" + "github.com/bounce-chat/go-i2p/lib/netdb" +) + +// i2p router type +type Router struct { + cfg *config.RouterConfig + ndb netdb.StdNetDB +} + + +func CreateRouter() (r *Router, err error) { + cfg := config.Router + r = &Router{ + cfg: cfg, + ndb: netdb.StdNetDB(cfg.NetDbDir), + } + return +} + +// run i2p router mainloop +func (r *Router) Run() { + r.ndb.Run() +} diff --git a/lib/ssu/doc.go b/lib/ssu/doc.go new file mode 100644 index 0000000..a949041 --- /dev/null +++ b/lib/ssu/doc.go @@ -0,0 +1,7 @@ +/* + +i2p ssu transport implementation + +*/ +package ssu + diff --git a/lib/ssu/packet.go b/lib/ssu/packet.go new file mode 100644 index 0000000..23fcb04 --- /dev/null +++ b/lib/ssu/packet.go @@ -0,0 +1 @@ +package ssu diff --git a/lib/ssu/session.go b/lib/ssu/session.go new file mode 100644 index 0000000..ab76969 --- /dev/null +++ b/lib/ssu/session.go @@ -0,0 +1,3 @@ +package ssu + + diff --git a/lib/stdi2p/RouterIdentity.go b/lib/stdi2p/RouterIdentity.go new file mode 100644 index 0000000..13e6b8e --- /dev/null +++ b/lib/stdi2p/RouterIdentity.go @@ -0,0 +1,7 @@ +package stdi2p + + +// Router Identity +type RouterIdentity struct { + +} diff --git a/lib/stdi2p/RouterInfo.go b/lib/stdi2p/RouterInfo.go new file mode 100644 index 0000000..2f79107 --- /dev/null +++ b/lib/stdi2p/RouterInfo.go @@ -0,0 +1,6 @@ +package stdi2p + + +type RouterInfo struct { + +} diff --git a/lib/stdi2p/i2np.go b/lib/stdi2p/i2np.go new file mode 100644 index 0000000..c3565c9 --- /dev/null +++ b/lib/stdi2p/i2np.go @@ -0,0 +1,2 @@ +package stdi2p + diff --git a/lib/stdi2p/su3.go b/lib/stdi2p/su3.go new file mode 100644 index 0000000..3021366 --- /dev/null +++ b/lib/stdi2p/su3.go @@ -0,0 +1,7 @@ +package stdi2p + + +// an su3 archive +type SU3 struct { + +} diff --git a/main.go b/main.go new file mode 100644 index 0000000..55e1fc0 --- /dev/null +++ b/main.go @@ -0,0 +1,26 @@ +package main + +import ( + + "github.com/bounce-chat/go-i2p/lib/router" + + "github.com/golang/glog" + "flag" +) + + + +func main() { + + flag.Parse() + + glog.Info("parsing i2p router configuration") + + glog.Info("starting up i2p router") + r, err := router.CreateRouter() + if err == nil { + r.Run() + } else { + glog.Errorf("failed to create i2p router: %s", err) + } +}