11 Commits

Author SHA1 Message Date
eyedeekay
627e131a58 Merge branch 'routerinfo' of https://github.com/hkh4n/go-i2p into routerinfo 2024-11-16 13:20:45 -05:00
idk
f729bda62d Merge branch 'master' into routerinfo 2024-11-16 18:17:10 +00:00
eyedeekay
4ad0f97bfe Fail-fast switch for logging Logging, format 2024-11-16 13:15:33 -05:00
eyedeekay
20032e0f55 Log: document fast-fail mode in the README. 2024-11-16 13:11:06 -05:00
eyedeekay
700391788f Log: create WARNFAIL_I2P environment variable, if not empty, all WARN or higher debug messages will result in an immediate fatal error and stop the program. 2024-11-16 12:52:26 -05:00
idk
e296441f29 Merge branch 'master' into routerinfo 2024-11-16 03:56:57 +00:00
Haris Khan
62086c7d04 make fmt 2024-11-15 22:52:17 -05:00
idk
df45c19272 Merge pull request #24 from satk0/fix-key-certificate-tests
Fix key certificate tests
2024-11-14 15:50:16 +00:00
satk0
f6894e9064 Fix PubKeyWithP521 test 2024-11-12 23:54:50 +01:00
satk0
b36ef65a10 Fix test when data is too small 2024-11-11 23:04:21 +01:00
eyedeekay
8c2b952616 setup auto-assign workflow 2024-11-08 15:01:05 -05:00
17 changed files with 152 additions and 37 deletions

20
.github/workflows/auto-assign.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Auto Assign
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
run:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: 'Auto-assign issue'
uses: pozil/auto-assign-issue@v1
with:
repo-token:${{ secrets.GITHUB_TOKEN }}
assignees: eyedeekay
numOfAssignee: 1

View File

@@ -94,7 +94,7 @@ please keep up with these changes, as they will not be backward compatible and r
- [X] Session Tag - [X] Session Tag
## Verbosity ## ## Verbosity ##
Logging can be enabled and configured using the DEBUG_I2P environment variable. By default, logging is disabled. Logging can be enabled and configured using the `DEBUG_I2P` environment variable. By default, logging is disabled.
There are three available log levels: There are three available log levels:
@@ -113,6 +113,17 @@ export DEBUG_I2P=error
If DEBUG_I2P is set to an unrecognized variable, it will fall back to "debug". If DEBUG_I2P is set to an unrecognized variable, it will fall back to "debug".
## Fast-Fail mode ##
Fast-Fail mode can be activated by setting `WARNFAIL_I2P` to any non-empty value. When set, every warning or error is Fatal.
It is unsafe for production use, and intended only for debugging and testing purposes.
```shell
export WARNFAIL_I2P=true
```
If `WARNFAIL_I2P` is set and `DEBUG_I2P` is unset, `DEBUG_I2P` will be set to `debug`.
## Contributing ## Contributing
See CONTRIBUTING.md for more information. See CONTRIBUTING.md for more information.

View File

@@ -155,7 +155,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
"reason": "duplicate key in mapping", "reason": "duplicate key in mapping",
"key": string(key_str), "key": string(key_str),
}).Error("mapping format violation") }).Error("mapping format violation")
log.Printf("DUPE: %s", key_str) log.Warnf("DUPE: %s", key_str)
errs = append(errs, errors.New("mapping format violation, duplicate key in mapping")) errs = append(errs, errors.New("mapping format violation, duplicate key in mapping"))
// Based on other implementations this does not seem to happen often? // Based on other implementations this does not seem to happen often?
// Java throws an exception in this case, the base object is a Hashmap so the value is overwritten and an exception is thrown. // Java throws an exception in this case, the base object is a Hashmap so the value is overwritten and an exception is thrown.
@@ -170,7 +170,7 @@ func ReadMappingValues(remainder []byte, map_length Integer) (values *MappingVal
"value:": string(remainder), "value:": string(remainder),
}).Warn("mapping format violation") }).Warn("mapping format violation")
errs = append(errs, errors.New("mapping format violation, expected =")) errs = append(errs, errors.New("mapping format violation, expected ="))
log.Printf("ERRVAL: %s", remainder) log.Warnf("ERRVAL: %s", remainder)
break break
} else { } else {
remainder = remainder[1:] remainder = remainder[1:]

View File

@@ -5,7 +5,7 @@ import common "github.com/go-i2p/go-i2p/lib/common/router_identity"
func Fuzz(data []byte) int { func Fuzz(data []byte) int {
router_identity, _, _ := common.ReadRouterIdentity(data) router_identity, _, _ := common.ReadRouterIdentity(data)
router_identity.Certificate() router_identity.Certificate()
//router_identity.publicKey() // router_identity.publicKey()
//router_identity.signingPublicKey() // router_identity.signingPublicKey()
return 0 return 0
} }

View File

@@ -123,7 +123,7 @@ func TestConstructSigningPublicKeyWithP521(t *testing.T) {
assert := assert.New(t) assert := assert.New(t)
key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x08, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}) key_cert, _, err := NewKeyCertificate([]byte{0x05, 0x00, 0x08, 0x00, 0x03, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00})
data := make([]byte, 128) data := make([]byte, 132)
spk, err := key_cert.ConstructSigningPublicKey(data) spk, err := key_cert.ConstructSigningPublicKey(data)
assert.Nil(err, "ConstructSigningPublicKey() with P521 returned err on valid data") assert.Nil(err, "ConstructSigningPublicKey() with P521 returned err on valid data")

View File

@@ -12,7 +12,7 @@ import (
func consolidateNetDb(sourcePath string, destPath string) error { func consolidateNetDb(sourcePath string, destPath string) error {
// Create destination directory if it doesn't exist // Create destination directory if it doesn't exist
if err := os.MkdirAll(destPath, 0755); err != nil { if err := os.MkdirAll(destPath, 0o755); err != nil {
return fmt.Errorf("failed to create destination directory: %v", err) return fmt.Errorf("failed to create destination directory: %v", err)
} }
@@ -68,7 +68,7 @@ func consolidateAllNetDbs(tempDir string) error {
i2pdPath := filepath.Join(os.Getenv("HOME"), ".i2pd/netDb") i2pdPath := filepath.Join(os.Getenv("HOME"), ".i2pd/netDb")
// Create the temp directory // Create the temp directory
if err := os.MkdirAll(tempDir, 0755); err != nil { if err := os.MkdirAll(tempDir, 0o755); err != nil {
return fmt.Errorf("failed to create temp directory: %v", err) return fmt.Errorf("failed to create temp directory: %v", err)
} }
@@ -88,12 +88,14 @@ func consolidateAllNetDbs(tempDir string) error {
return nil return nil
} }
func cleanupTempDir(path string) error { func cleanupTempDir(path string) error {
if err := os.RemoveAll(path); err != nil { if err := os.RemoveAll(path); err != nil {
return fmt.Errorf("failed to cleanup temporary directory %s: %v", path, err) return fmt.Errorf("failed to cleanup temporary directory %s: %v", path, err)
} }
return nil return nil
} }
func createTempNetDbDir() (string, error) { func createTempNetDbDir() (string, error) {
// Get system's temp directory in a platform-independent way // Get system's temp directory in a platform-independent way
baseDir := os.TempDir() baseDir := os.TempDir()
@@ -106,13 +108,14 @@ func createTempNetDbDir() (string, error) {
tempDir := filepath.Join(baseDir, dirName) tempDir := filepath.Join(baseDir, dirName)
// Create the directory with appropriate permissions // Create the directory with appropriate permissions
err := os.MkdirAll(tempDir, 0755) err := os.MkdirAll(tempDir, 0o755)
if err != nil { if err != nil {
return "", fmt.Errorf("failed to create temporary directory: %v", err) return "", fmt.Errorf("failed to create temporary directory: %v", err)
} }
return tempDir, nil return tempDir, nil
} }
func Test10K(t *testing.T) { func Test10K(t *testing.T) {
i2pPath := filepath.Join(os.Getenv("HOME"), ".i2p/netDb") i2pPath := filepath.Join(os.Getenv("HOME"), ".i2p/netDb")
i2pdPath := filepath.Join(os.Getenv("HOME"), ".i2pd/netDb") i2pdPath := filepath.Join(os.Getenv("HOME"), ".i2pd/netDb")
@@ -128,7 +131,7 @@ func Test10K(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to create temp directory: %v", err) t.Fatalf("Failed to create temp directory: %v", err)
} }
//defer cleanupTempDir(tempDir) // defer cleanupTempDir(tempDir)
if err := consolidateAllNetDbs(tempDir); err != nil { if err := consolidateAllNetDbs(tempDir); err != nil {
t.Fatalf("Failed to consolidate netDbs: %v", err) t.Fatalf("Failed to consolidate netDbs: %v", err)
@@ -156,7 +159,7 @@ func Test10K(t *testing.T) {
} }
// Parse the router info // Parse the router info
//fmt.Printf("data: %s\n", string(data)) // fmt.Printf("data: %s\n", string(data))
routerInfo, _, err := ReadRouterInfo(data) routerInfo, _, err := ReadRouterInfo(data)
if err != nil { if err != nil {
t.Logf("Failed to parse router info from %s: %v", file.Name(), err) t.Logf("Failed to parse router info from %s: %v", file.Name(), err)
@@ -170,7 +173,7 @@ func Test10K(t *testing.T) {
continue continue
} }
err = os.WriteFile(filepath.Join(targetDir, file.Name()), routerBytes, 0644) err = os.WriteFile(filepath.Join(targetDir, file.Name()), routerBytes, 0o644)
if err != nil { if err != nil {
t.Logf("Failed to write router info %s: %v", file.Name(), err) t.Logf("Failed to write router info %s: %v", file.Name(), err)
continue continue

View File

@@ -4,11 +4,12 @@ package router_info
import ( import (
"encoding/binary" "encoding/binary"
"errors" "errors"
"github.com/go-i2p/go-i2p/lib/common/certificate"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/go-i2p/go-i2p/lib/common/certificate"
"github.com/go-i2p/go-i2p/lib/crypto" "github.com/go-i2p/go-i2p/lib/crypto"
"github.com/go-i2p/go-i2p/lib/util/logger" "github.com/go-i2p/go-i2p/lib/util/logger"
@@ -174,7 +175,7 @@ func (router_info *RouterInfo) RouterIdentity() *RouterIdentity {
// IndentHash returns the identity hash (sha256 sum) for this RouterInfo. // IndentHash returns the identity hash (sha256 sum) for this RouterInfo.
func (router_info *RouterInfo) IdentHash() Hash { func (router_info *RouterInfo) IdentHash() Hash {
log.Debug("Calculating IdentHash for RouterInfo") log.Debug("Calculating IdentHash for RouterInfo")
//data, _ := router_info.RouterIdentity().keyCertificate.Data() // data, _ := router_info.RouterIdentity().keyCertificate.Data()
cert := router_info.RouterIdentity().KeysAndCert.Certificate() cert := router_info.RouterIdentity().KeysAndCert.Certificate()
data := cert.Data() data := cert.Data()
hash := HashData(data) hash := HashData(data)

View File

@@ -4,10 +4,11 @@ import (
"bytes" "bytes"
"crypto/rand" "crypto/rand"
"encoding/binary" "encoding/binary"
"github.com/go-i2p/go-i2p/lib/common/signature"
"testing" "testing"
"time" "time"
"github.com/go-i2p/go-i2p/lib/common/signature"
"github.com/go-i2p/go-i2p/lib/common/certificate" "github.com/go-i2p/go-i2p/lib/common/certificate"
"github.com/go-i2p/go-i2p/lib/common/data" "github.com/go-i2p/go-i2p/lib/common/data"
"github.com/go-i2p/go-i2p/lib/common/router_address" "github.com/go-i2p/go-i2p/lib/common/router_address"

View File

@@ -3,6 +3,7 @@ package signature
import ( import (
"fmt" "fmt"
"github.com/go-i2p/go-i2p/lib/util/logger" "github.com/go-i2p/go-i2p/lib/util/logger"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )

View File

@@ -185,7 +185,7 @@ func (v *Ed25519Verifier) Verify(data, sig []byte) (err error) {
type Ed25519PrivateKey ed25519.PrivateKey type Ed25519PrivateKey ed25519.PrivateKey
func (k Ed25519PrivateKey) NewDecrypter() (Decrypter, error) { func (k Ed25519PrivateKey) NewDecrypter() (Decrypter, error) {
//TODO implement me // TODO implement me
panic("implement me") panic("implement me")
} }

View File

@@ -30,7 +30,7 @@ type SigningPublicKey interface {
} }
type PublicKey interface { type PublicKey interface {
Len() int Len() int
Bytes() []byte Bytes() []byte
NewEncrypter() (Encrypter, error) NewEncrypter() (Encrypter, error)
} }

View File

@@ -76,7 +76,7 @@ func (r Reseed) SingleReseed(uri string) ([]router_info.RouterInfo, error) {
log.WithError(err).Error("Failed to read SU3 file signature") log.WithError(err).Error("Failed to read SU3 file signature")
return nil, err return nil, err
} }
log.Println("warning: this doesn't validate the signature yet", signature) log.Debug("warning: this doesn't validate the signature yet", signature)
log.Warn("Doesn't validate the signature yet", logrus.Fields{"signature": signature}) log.Warn("Doesn't validate the signature yet", logrus.Fields{"signature": signature})
} }
zip := filepath.Join(config.RouterConfigProperties.NetDb.Path, "reseed.zip") zip := filepath.Join(config.RouterConfigProperties.NetDb.Path, "reseed.zip")

View File

@@ -152,7 +152,7 @@ func (db *StdNetDB) RecalculateSize() (err error) {
} }
if db.CheckFilePathValid(fname) { if db.CheckFilePathValid(fname) {
log.WithField("file_name", fname).Debug("Reading RouterInfo file") log.WithField("file_name", fname).Debug("Reading RouterInfo file")
log.Println("Reading in file:", fname) log.Debug("Reading in file:", fname)
b, err := os.ReadFile(fname) b, err := os.ReadFile(fname)
if err != nil { if err != nil {
log.WithError(err).Error("Failed to read RouterInfo file") log.WithError(err).Error("Failed to read RouterInfo file")
@@ -165,9 +165,9 @@ func (db *StdNetDB) RecalculateSize() (err error) {
} }
ih := ri.IdentHash().Bytes() ih := ri.IdentHash().Bytes()
log.WithError(err).Error("Failed to parse RouterInfo") log.WithError(err).Error("Failed to parse RouterInfo")
log.Printf("Read in IdentHash: %s", base32.EncodeToString(ih[:])) log.Debugf("Read in IdentHash: %s", base32.EncodeToString(ih[:]))
for _, addr := range ri.RouterAddresses() { for _, addr := range ri.RouterAddresses() {
log.Println(string(addr.Bytes())) log.Debug(string(addr.Bytes()))
log.WithField("address", string(addr.Bytes())).Debug("RouterInfo address") log.WithField("address", string(addr.Bytes())).Debug("RouterInfo address")
} }
if ent, ok := db.RouterInfos[ih]; !ok { if ent, ok := db.RouterInfos[ih]; !ok {
@@ -177,13 +177,13 @@ func (db *StdNetDB) RecalculateSize() (err error) {
} }
} else { } else {
log.Debug("RouterInfo already in memory cache") log.Debug("RouterInfo already in memory cache")
log.Println("entry previously found in table", ent, fname) log.Debug("entry previously found in table", ent, fname)
} }
ri = router_info.RouterInfo{} ri = router_info.RouterInfo{}
count++ count++
} else { } else {
log.WithField("file_path", fname).Warn("Invalid file path") log.WithField("file_path", fname).Warn("Invalid file path")
log.Println("Invalid path error") log.Debug("Invalid path error")
} }
return err return err
}) })

View File

@@ -36,7 +36,7 @@ func (c *NoiseSession) RunIncomingHandshake() error {
} }
log.Debug("Handshake message written successfully") log.Debug("Handshake message written successfully")
log.WithField("state", state).Debug("Handshake state after message write") log.WithField("state", state).Debug("Handshake state after message write")
log.Println(state) log.Debug(state)
c.handshakeComplete = true c.handshakeComplete = true
log.Debug("Incoming handshake completed successfully") log.Debug("Incoming handshake completed successfully")
return nil return nil

View File

@@ -39,7 +39,7 @@ func (c *NoiseSession) RunOutgoingHandshake() error {
} }
log.Debug("Handshake message written successfully") log.Debug("Handshake message written successfully")
log.WithField("state", state).Debug("Handshake state after message write") log.WithField("state", state).Debug("Handshake state after message write")
log.Println(state) log.Debug(state)
c.handshakeComplete = true c.handshakeComplete = true
log.Debug("Outgoing handshake completed successfully") log.Debug("Outgoing handshake completed successfully")
return nil return nil

View File

@@ -21,11 +21,11 @@ type NoiseSession struct {
*sync.Cond *sync.Cond
*NoiseTransport // The parent transport, which "Dialed" the connection to the peer whith whom we established the session *NoiseTransport // The parent transport, which "Dialed" the connection to the peer whith whom we established the session
*HandshakeState *HandshakeState
RecvQueue *cb.Queue RecvQueue *cb.Queue
SendQueue *cb.Queue SendQueue *cb.Queue
VerifyCallback VerifyCallbackFunc VerifyCallback VerifyCallbackFunc
activeCall int32 activeCall int32
Conn net.Conn Conn net.Conn
} }
// RemoteAddr implements net.Conn // RemoteAddr implements net.Conn

View File

@@ -1,7 +1,7 @@
package logger package logger
import ( import (
"io/ioutil" "io"
"os" "os"
"strings" "strings"
"sync" "sync"
@@ -10,18 +10,96 @@ import (
) )
var ( var (
log *logrus.Logger log *Logger
once sync.Once once sync.Once
failFast string
) )
// Logger wraps logrus.Logger and adds the ability to make all warnings fatal
type Logger struct {
*logrus.Logger
}
// Entry wraps logrus.Entry and enables it to use our Logger
type Entry struct {
Logger
entry *logrus.Entry
}
// Warn wraps logrus.Warn and logs a fatal error if failFast is set
func (l *Logger) Warn(args ...interface{}) {
warnFatal(args)
l.Logger.Warn(args...)
}
// Warnf wraps logrus.Warnf and logs a fatal error if failFast is set
func (l *Logger) Warnf(format string, args ...interface{}) {
warnFatalf(format, args...)
l.Logger.Warnf(format, args...)
}
// Error wraps logrus.Error and logs a fatal error if failFast is set
func (l *Logger) Error(args ...interface{}) {
warnFatal(args)
l.Logger.Error(args...)
}
// Errorf wraps logrus.Errorf and logs a fatal error if failFast is set
func (l *Logger) Errorf(format string, args ...interface{}) {
warnFatalf(format, args...)
l.Logger.Errorf(format, args...)
}
// WithField wraps logrus.WithField and returns an Entry
func (l *Logger) WithField(key string, value interface{}) *Entry {
entry := l.Logger.WithField(key, value)
return &Entry{*l, entry}
}
// WithFields wraps logrus.WithFields and returns an Entry
func (l *Logger) WithFields(fields logrus.Fields) *Entry {
entry := l.Logger.WithFields(fields)
return &Entry{*l, entry}
}
// WithError wraps logrus.WithError and returns an Entry
func (l *Logger) WithError(err error) *Entry {
entry := l.Logger.WithError(err)
return &Entry{*l, entry}
}
func warnFatal(args ...interface{}) {
if failFast != "" {
log.Fatal(args)
}
}
func warnFatalf(format string, args ...interface{}) {
if failFast != "" {
log.Fatalf(format, args...)
}
}
func warnFail() {
if failFast != "" {
log.Error("FATAL ERROR")
}
}
// InitializeGoI2PLogger sets up all the necessary logging
func InitializeGoI2PLogger() { func InitializeGoI2PLogger() {
once.Do(func() { once.Do(func() {
log = logrus.New() log = &Logger{}
log.Logger = logrus.New()
// We do not want to log by default // We do not want to log by default
log.SetOutput(ioutil.Discard) log.SetOutput(io.Discard)
log.SetLevel(logrus.PanicLevel) log.SetLevel(logrus.PanicLevel)
// Check if DEBUG_I2P is set // Check if DEBUG_I2P is set
if logLevel := os.Getenv("DEBUG_I2P"); logLevel != "" { if logLevel := os.Getenv("DEBUG_I2P"); logLevel != "" {
failFast = os.Getenv("WARNFAIL_I2P")
if failFast != "" && logLevel == "" {
logLevel = "debug"
}
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
switch strings.ToLower(logLevel) { switch strings.ToLower(logLevel) {
case "debug": case "debug":
@@ -38,8 +116,8 @@ func InitializeGoI2PLogger() {
}) })
} }
// GetGoI2PLogger returns the initialized logger // GetGoI2PLogger returns the initialized Logger
func GetGoI2PLogger() *logrus.Logger { func GetGoI2PLogger() *Logger {
if log == nil { if log == nil {
InitializeGoI2PLogger() InitializeGoI2PLogger()
} }