gopeer

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: MIT Imports: 20 Imported by: 0

README

gopeer

Framework for create decentralized networks. Version: 1.2.3s.

Framework based applications:
Specifications:
  • Protocol: TCP;
  • 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(3 << 10),
        "SKEY_SIZE": uint(1 << 5),
    })
}

func main() {
    node := gp.NewClient(gp.GeneratePrivate(gp.Get("AKEY_SIZE").(uint)), handleFunc)
    gp.NewNode(":8080", node).Run()
    // ...
}

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 << 4,  // 2^4B = 16B
    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(3 << 10),
    "SKEY_SIZE": uint(1 << 5),
})
Network functions and methods:
// CREATE
func NewNode(address string, client *Client) *Node {}
func NewClient(priv *rsa.PrivateKey, handle func(*Client, *Package)) *Client {}
func NewPackage(title, data string) *Package {}
// ACTIONS
func Handle(title string, client *Client, pack *Package, handle func(*Client, *Package) string) {}
func (listener *Node) Run() error {}
func (client *Client) Send(receiver *rsa.PublicKey, pack *Package, route []*rsa.PublicKey, pseudoSender *Client) (string, error) {}
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 {}
// KEYS
func (client *Client) Public() *rsa.PublicKey {}
func (client *Client) Private() *rsa.PrivateKey {}
func (client *Client) StringPublic() string {}
func (client *Client) StringPrivate() string {}
func (client *Client) HashPublic() string {}
// F2F
func (client *Client) F2F() bool {}
func (client *Client) EnableF2F() {}
func (client *Client) DisableF2F() {}
func (client *Client) InF2F(pub *rsa.PublicKey) bool {}
func (client *Client) ListF2F() []rsa.PublicKey {}
func (client *Client) AppendF2F(pub *rsa.PublicKey) {}
func (client *Client) RemoveF2F(pub *rsa.PublicKey) {}
Cryptography functions:
func GenerateBytes(max uint) []byte {}
func GeneratePrivate(bits uint) *rsa.PrivateKey {}
func HashPublic(pub *rsa.PublicKey) string {}
func HashSum(data []byte) []byte {}
func ParsePrivate(privData string) *rsa.PrivateKey {}
func ParsePublic(pubData string) *rsa.PublicKey {}
func StringPrivate(priv *rsa.PrivateKey) string {}
func StringPublic(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 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,
    },
}
Listener structure:
{
    address: string,
    client:  *Client,
    listen:  net.Listener,
}
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:         {
        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 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 GeneratePrivate

func GeneratePrivate(bits uint) *rsa.PrivateKey

func Get

func Get(key string) interface{}

func Handle added in v1.2.0

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

func HashPublic

func HashPublic(pub *rsa.PublicKey) string

func HashSum

func HashSum(data []byte) []byte

func ParsePrivate

func ParsePrivate(privData string) *rsa.PrivateKey

func ParsePublic

func ParsePublic(pubData string) *rsa.PublicKey

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 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 StringPrivate

func StringPrivate(priv *rsa.PrivateKey) string

func StringPublic

func StringPublic(pub *rsa.PublicKey) string

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 {
	// contains filtered or unexported fields
}

func NewClient added in v1.2.0

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

func (*Client) AppendF2F added in v1.2.0

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

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) DisableF2F added in v1.2.0

func (client *Client) DisableF2F()

func (*Client) Disconnect

func (client *Client) Disconnect(address string)

func (*Client) EnableF2F added in v1.2.0

func (client *Client) EnableF2F()

func (*Client) Encrypt added in v1.2.3

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

func (*Client) F2F added in v1.1.1

func (client *Client) F2F() bool

func (*Client) HashPublic added in v1.2.0

func (client *Client) HashPublic() string

func (*Client) InF2F added in v1.2.0

func (client *Client) InF2F(pub *rsa.PublicKey) bool

func (*Client) ListF2F added in v1.2.0

func (client *Client) ListF2F() []rsa.PublicKey

func (*Client) Private added in v1.1.2

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

func (*Client) Public added in v1.1.2

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

func (*Client) RemoveF2F added in v1.2.0

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

func (*Client) Send added in v1.2.0

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

func (*Client) StringPrivate added in v1.2.0

func (client *Client) StringPrivate() string

func (*Client) StringPublic added in v1.2.0

func (client *Client) StringPublic() string

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 Node added in v1.2.3

type Node struct {
	// contains filtered or unexported fields
}

func NewNode added in v1.2.3

func NewNode(address string, client *Client) *Node

func (*Node) Run added in v1.2.3

func (node *Node) Run() error

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