gopeer

package module
v1.2.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 25, 2021 License: MIT Imports: 20 Imported by: 0

README

gopeer

Framework for create decentralized networks. Version: 1.2.6s.

Framework based applications
Research Article
Specifications
  • Type: Embedded;
  • Protocol: TCP;
  • Routing: Fill;
  • Encryption: E2E;
  • Symmetric algorithm: AES-CBC;
  • Asymmetric algorithm: RSA-OAEP, RSA-PSS;
  • Hash function: SHA256;
Template
package main

import (
    gp "./gopeer"
)

func init() {
    gp.Set(gp.SettingsType{
        "AKEY_SIZE": uint(1 << 10),
        "SKEY_SIZE": uint(1 << 4),
    })
}

func main() {
    gp.NewClient(
        gp.GenerateKey(gp.Get("AKEY_SIZE").(uint)), 
        handleFunc,
    ).RunNode(":8080")
    // ...
}

func handleFunc(client *gp.Client, pack *gp.Package) {
    // ...
}
Settings
type SettingsType map[string]interface{}
type settingsStruct struct {
    END_BYTES string
    ROUTE_MSG string
    RETRY_NUM uint
    WAIT_TIME uint
    POWS_DIFF uint
    CONN_SIZE uint
    BUFF_SIZE uint
    PACK_SIZE uint
    MAPP_SIZE uint
    AKEY_SIZE uint
    SKEY_SIZE uint
    RAND_SIZE uint
}
Default settings
{
    END_BYTES: "\000\005\007\001\001\007\005\000",
    ROUTE_MSG: "\000\001\002\003\004\005\006\007",
    RETRY_NUM: 3,       // quantity
    WAIT_TIME: 20,      // seconds
    POWS_DIFF: 20,      // bits
    CONN_SIZE: 10,      // quantity
    BUFF_SIZE: 2 << 20, // 2*(2^20)B = 2MiB
    PACK_SIZE: 4 << 20, // 4*(2^20)B = 4MiB
    MAPP_SIZE: 2 << 10, // 2*(2^10)H = 88KiB
    AKEY_SIZE: 2 << 10, // 2*(2^10)b = 256B
    SKEY_SIZE: 1 << 5,  // 2^5B = 32B
    RAND_SIZE: 1 << 4,  // 2^4B = 16B
}
Settings functions
func Set(settings SettingsType) []uint8 {}
func Get(key string) interface{} {}
Get/Set settings example
var AKEY_SIZE = gopeer.Get("AKEY_SIZE").(uint)
gopeer.Set(gopeer.SettingsType{
    "AKEY_SIZE": uint(1 << 10),
    "SKEY_SIZE": uint(1 << 4),
})
Network functions and methods
func NewClient(priv *rsa.PrivateKey, handle func(*Client, *Package)) *Client {}
func NewPackage(title, data string) *Package {}
func (client *Client) Handle(title string, pack *Package, handle func(*Client, *Package) string) {}
func (client *Client) RunNode(address string) error {}
func (client *Client) Send(receiver *rsa.PublicKey, pack *Package, route []*rsa.PublicKey, ppsender *rsa.PrivateKey) (string, error) {}
func (client *Client) RoutePackage(receiver *rsa.PublicKey, pack *Package, route []*rsa.PublicKey, ppsender *rsa.PrivateKey) *Package {}
func (client *Client) Connect(address string) error {}
func (client *Client) Disconnect(address string) {}
func (client *Client) Encrypt(receiver *rsa.PublicKey, pack *Package) *Package {}
func (client *Client) Decrypt(pack *Package) *Package {}
func (client *Client) PublicKey() *rsa.PublicKey {}
func (client *Client) PrivateKey() *rsa.PrivateKey {}
func (f2f *friendToFriend) State() bool {}
func (f2f *friendToFriend) Switch() {}
func (f2f *friendToFriend) List() []rsa.PublicKey {}
func (f2f *friendToFriend) InList(pub *rsa.PublicKey) bool {}
func (f2f *friendToFriend) Append(pub *rsa.PublicKey) {}
func (f2f *friendToFriend) Remove(pub *rsa.PublicKey) {}
Cryptography functions
func GenerateBytes(max uint) []byte {}
func GenerateKey(bits uint) *rsa.PrivateKey {}
func HashSum(data []byte) []byte {}
func HashPublicKey(pub *rsa.PublicKey) string {}
func BytesToPrivateKey(privData []byte) *rsa.PrivateKey {}
func BytesToPublicKey(pubData []byte) *rsa.PublicKey {}
func StringToPrivateKey(privData string) *rsa.PrivateKey {}
func StringToPublicKey(pubData string) *rsa.PublicKey {}
func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte {}
func PublicKeyToBytes(pub *rsa.PublicKey) []byte {}
func PrivateKeyToString(priv *rsa.PrivateKey) string {}
func PublicKeyToString(pub *rsa.PublicKey) string {}
func EncryptRSA(pub *rsa.PublicKey, data []byte) []byte {}
func DecryptRSA(priv *rsa.PrivateKey, data []byte) []byte {}
func Sign(priv *rsa.PrivateKey, data []byte) []byte {}
func Verify(pub *rsa.PublicKey, data, sign []byte) error {}
func EncryptAES(key, data []byte) []byte {}
func DecryptAES(key, data []byte) []byte {}
func RaiseEntropy(info, salt []byte, bits int) []byte {}
func ProofOfWork(packHash []byte, diff uint) uint64 {}
func ProofIsValid(packHash []byte, diff uint, nonce uint64) bool {}
Additional functions
func SerializePackage(pack *Package) string {}
func DeserializePackage(jsonData string) *Package {}
func Base64Encode(data []byte) string {}
func Base64Decode(data string) []byte {}
Package structure
{
    Head: {
        Rand:    string,
        Title:   string,
        Sender:  string,
        Session: string,
    },
    Body: {
        Data: string,
        Hash: string,
        Sign: string,
        Npow: uint64,
    },
}
Client structure
{
    handle:      func(*Client, *Package)
    mutex:       sync.Mutex,
    privateKey:  *rsa.PrivateKey,
    mapping:     map[string]bool,
    connections: map[net.Conn]string,
    actions:     map[string]chan bool,
    F2F:         {
        mutex:   sync.Mutex,
        enabled: bool,
        friends: map[string]*rsa.PublicKey,
    },
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base64Decode

func Base64Decode(data string) []byte

func Base64Encode

func Base64Encode(data []byte) string

func BytesToPrivateKey added in v1.2.6

func BytesToPrivateKey(privData []byte) *rsa.PrivateKey

func BytesToPublicKey added in v1.2.6

func BytesToPublicKey(pubData []byte) *rsa.PublicKey

func DecryptAES

func DecryptAES(key, data []byte) []byte

func DecryptRSA

func DecryptRSA(priv *rsa.PrivateKey, data []byte) []byte

func EncryptAES

func EncryptAES(key, data []byte) []byte

func EncryptRSA

func EncryptRSA(pub *rsa.PublicKey, data []byte) []byte

func GenerateBytes added in v1.2.0

func GenerateBytes(max uint) []byte

func GenerateKey added in v1.2.6

func GenerateKey(bits uint) *rsa.PrivateKey

func Get

func Get(key string) interface{}

func HashPublicKey added in v1.2.6

func HashPublicKey(pub *rsa.PublicKey) string

func HashSum

func HashSum(data []byte) []byte

func PrivateKeyToBytes added in v1.2.6

func PrivateKeyToBytes(priv *rsa.PrivateKey) []byte

func PrivateKeyToString added in v1.2.6

func PrivateKeyToString(priv *rsa.PrivateKey) string

func ProofIsValid added in v1.2.1

func ProofIsValid(packHash []byte, diff uint, nonce uint64) bool

func ProofOfWork

func ProofOfWork(packHash []byte, diff uint) uint64

func PublicKeyToBytes added in v1.2.6

func PublicKeyToBytes(pub *rsa.PublicKey) []byte

func PublicKeyToString added in v1.2.6

func PublicKeyToString(pub *rsa.PublicKey) string

func RaiseEntropy added in v1.2.6

func RaiseEntropy(info, salt []byte, bits int) []byte

func SerializePackage added in v1.2.2

func SerializePackage(pack *Package) string

func Set

func Set(settings SettingsType) []uint8

func Sign

func Sign(priv *rsa.PrivateKey, data []byte) []byte

func StringToPrivateKey added in v1.2.6

func StringToPrivateKey(privData string) *rsa.PrivateKey

func StringToPublicKey added in v1.2.6

func StringToPublicKey(pubData string) *rsa.PublicKey

func ToBytes

func ToBytes(num uint64) []byte

func Verify

func Verify(pub *rsa.PublicKey, data, sign []byte) error

Types

type BodyPackage added in v1.2.0

type BodyPackage struct {
	Data string `json:"data"`
	Hash string `json:"hash"`
	Sign string `json:"sign"`
	Npow uint64 `json:"npow"`
}

type Client

type Client struct {
	F2F *friendToFriend
	// contains filtered or unexported fields
}

func NewClient added in v1.2.0

func NewClient(priv *rsa.PrivateKey, handle func(*Client, *Package)) *Client

func (*Client) Connect

func (client *Client) Connect(address string) error

func (*Client) Decrypt added in v1.2.3

func (client *Client) Decrypt(pack *Package) *Package

func (*Client) Disconnect

func (client *Client) Disconnect(address string)

func (*Client) Encrypt added in v1.2.3

func (client *Client) Encrypt(receiver *rsa.PublicKey, pack *Package) *Package

func (*Client) Handle added in v1.2.5

func (client *Client) Handle(title string, pack *Package, handle func(*Client, *Package) string)

func (*Client) PrivateKey added in v1.2.6

func (client *Client) PrivateKey() *rsa.PrivateKey

func (*Client) PublicKey added in v1.2.6

func (client *Client) PublicKey() *rsa.PublicKey

func (*Client) RoutePackage added in v1.2.6

func (client *Client) RoutePackage(receiver *rsa.PublicKey, pack *Package, route []*rsa.PublicKey, ppsender *rsa.PrivateKey) *Package

func (*Client) RunNode added in v1.2.5

func (client *Client) RunNode(address string) error

func (*Client) Send added in v1.2.0

func (client *Client) Send(receiver *rsa.PublicKey, pack *Package, route []*rsa.PublicKey, ppsender *rsa.PrivateKey) (string, error)

type HeadPackage added in v1.2.0

type HeadPackage struct {
	Rand    string `json:"rand"`
	Title   string `json:"title"`
	Sender  string `json:"sender"`
	Session string `json:"session"`
}

type Package

type Package struct {
	Head HeadPackage `json:"head"`
	Body BodyPackage `json:"body"`
}

func DeserializePackage added in v1.2.2

func DeserializePackage(jsonData string) *Package

func NewPackage added in v1.2.3

func NewPackage(title, data string) *Package

type SettingsType

type SettingsType map[string]interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL