Skip to content

go-i2p/common

Repository files navigation

go-i2p/common

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.


Installation

go mod init your-project
go get github.com/go-i2p/common

Usage

Basic Certificate Parsing

package 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))
}

Working with Destinations

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)
}

Parsing Router Information

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)
}

Working with I2P Strings

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)
}

Requirements

  • Go Version: 1.24.2 or later
  • Dependencies:
    • github.com/go-i2p/go-i2p - Core I2P library
    • github.com/go-i2p/logger - Structured logging wrapper
    • github.com/samber/oops - Enhanced error handling
    • github.com/sirupsen/logrus - Logging framework
    • github.com/stretchr/testify - Testing utilities

Testing

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/

License

MIT License - see LICENSE file for details.

Copyright (c) 2025 I2P For Go

About

Common library for go-i2p, factored out from the router to a separate package.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages