A comprehensive Go library implementing I2P (Invisible Internet Project) network protocol common data structures and utilities. This library provides type-safe implementations of the I2P specification common structures, factored out from the main I2P router to enable reusable components for parsing, encoding, and manipulating I2P network data.
go mod init your-project
go get github.com/go-i2p/commonpackage main
import (
"fmt"
"github.com/go-i2p/common/certificate"
)
func main() {
// Parse I2P certificate from binary data
data := []byte{0x00, 0x00, 0x02, 0xff, 0xff}
cert, remainder, err := certificate.ReadCertificate(data)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Certificate type: %d\n", cert.Type())
fmt.Printf("Certificate length: %d\n", cert.Length())
fmt.Printf("Remaining bytes: %d\n", len(remainder))
}package main
import (
"fmt"
"github.com/go-i2p/common/destination"
)
func main() {
// Read destination from binary data
data := []byte{/* destination bytes */}
dest, remainder, err := destination.ReadDestination(data)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Generate I2P addresses
base32Address := dest.Base32Address()
base64Address := dest.Base64()
fmt.Printf("Base32 address: %s\n", base32Address)
fmt.Printf("Base64 address: %s\n", base64Address)
}package main
import (
"fmt"
"github.com/go-i2p/common/router_info"
)
func main() {
// Read router info from binary data
data := []byte{/* router info bytes */}
routerInfo, remainder, err := router_info.ReadRouterInfo(data)
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
// Access router information
identity := routerInfo.RouterIdentity()
addresses := routerInfo.RouterAddresses()
capabilities := routerInfo.RouterCapabilities()
fmt.Printf("Router identity: %v\n", identity)
fmt.Printf("Router addresses: %d\n", len(addresses))
fmt.Printf("Router capabilities: %s\n", capabilities)
}package main
import (
"fmt"
"github.com/go-i2p/common/data"
)
func main() {
// Parse I2P string from binary data
stringData := []byte{0x05, 'h', 'e', 'l', 'l', 'o'}
i2pString := data.I2PString(stringData)
length, err := i2pString.Length()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
content, err := i2pString.Data()
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("String length: %d\n", length)
fmt.Printf("String content: %s\n", content)
}- Go Version: 1.24.2 or later
- Dependencies:
github.com/go-i2p/go-i2p- Core I2P librarygithub.com/go-i2p/logger- Structured logging wrappergithub.com/samber/oops- Enhanced error handlinggithub.com/sirupsen/logrus- Logging frameworkgithub.com/stretchr/testify- Testing utilities
Run the comprehensive test suite:
# Run all tests
make test
# Run specific component tests
go test ./certificate/...
go test ./destination/...
go test ./router_info/...
# Run fuzz tests
go test -fuzz=FuzzCertificate ./certificate/MIT License - see LICENSE file for details.
Copyright (c) 2025 I2P For Go