proto

package
v0.0.0-...-f60ece2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package proto - Core of p2p protocol

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalcSharedSecret

func CalcSharedSecret(publicKey []byte, privateKey []byte) (secret [32]byte)

CalcSharedSecret Calculate shared secret

func CreateKeyExchangePair

func CreateKeyExchangePair() (publicKey [32]byte, privateKey [32]byte)

CreateKeyExchangePair create pair for ECDHE

func Decrypt

func Decrypt(encrypted []byte, key []byte) []byte

Decrypt encrypted message

func Encrypt

func Encrypt(content []byte, key []byte) []byte

Encrypt the message

func LoadKey

func LoadKey(name string) (publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey)

LoadKey load key from file

func SaveKey

func SaveKey(fileName string) *os.File

SaveKey create new *.seed file with random content

Types

type Envelope

type Envelope struct {
	Cmd     []byte
	Id      []byte
	From    []byte
	To      []byte
	Sign    []byte
	Length  uint16
	Content []byte
}

Envelope Конверт для сообщений между пирами

func NewEnvelope

func NewEnvelope(cmd string, contentBytes []byte) (envelope *Envelope)

NewEnvelope Создание нового конверта

func NewSignedEnvelope

func NewSignedEnvelope(cmd string, from []byte, to []byte, sign []byte, contentBytes []byte) (envelope *Envelope)

NewSignedEnvelope create new envelop with signature

func ReadEnvelope

func ReadEnvelope(reader *bufio.Reader) (*Envelope, error)

ReadEnvelope Формирование конверта из байтов ридера сокета

func UnSerialize

func UnSerialize(b []byte) (envelope *Envelope)

UnSerialize Десериализация массива байт в конверт с содержимым

func (Envelope) Send

func (m Envelope) Send(peer *Peer)

Send send envelop to peer

func (Envelope) Serialize

func (m Envelope) Serialize() []byte

Serialize Сериализация конверта и содержимого в массив байт

func (Envelope) String

func (m Envelope) String() string

type HandShake

type HandShake struct {
	Name   string `json:"name"`
	PubKey string `json:"id"`
	ExKey  string `json:"exKey"`
}

HandShake type for handshake on connection

func (HandShake) ToJson

func (v HandShake) ToJson() []byte

ToJson convert to JSON bytes

type Peer

type Peer struct {
	PubKey    ed25519.PublicKey
	Conn      *net.Conn
	Name      string
	FirstSeen string
	LastSeen  string
	Peers     *Peers
	SharedKey SharedKey
}

Peer basic struct to describe peer

func NewPeer

func NewPeer(conn net.Conn) *Peer

NewPeer create new peer struct by socket connection

func (Peer) String

func (p Peer) String() string

func (*Peer) UpdatePeer

func (p *Peer) UpdatePeer(envelope *Envelope) error

UpdatePeer Update peer struct after handshake

type PeerName

type PeerName struct {
	Name   string `json:"name"`
	PubKey string `json:"id"`
}

PeerName Peer name and public key

func (PeerName) ToJson

func (v PeerName) ToJson() []byte

ToJson convert to JSON bytes

type Peers

type Peers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Peers synchronised list of peers

func NewPeers

func NewPeers() *Peers

NewPeers create new list of peers

func (Peers) Get

func (p Peers) Get(key string) (peer *Peer, found bool)

Get find and get peer in list

func (Peers) PeerList

func (p Peers) PeerList() *WsPeerList

PeerList return json list of peers

func (Peers) Put

func (p Peers) Put(peer *Peer)

Put put new peer to list

func (Peers) Remove

func (p Peers) Remove(peer *Peer) (found bool)

Remove remove peer from list

type Proto

type Proto struct {
	Port   int
	Name   string
	Peers  *Peers
	PubKey ed25519.PublicKey

	Broker chan *Envelope
	// contains filtered or unexported fields
}

Proto Ядро протокола

func NewProto

func NewProto(name string, port int) *Proto

NewProto - создание экземпляра ядра протокола

func (Proto) HandleProto

func (p Proto) HandleProto(rw *bufio.ReadWriter, peer *Peer)

HandleProto Обработка входящих сообщений

func (Proto) ListenPeer

func (p Proto) ListenPeer(peer *Peer)

ListenPeer Старт прослушивания соединения с пиром

func (Proto) MyName

func (p Proto) MyName() *PeerName

MyName return current peer name with public key

func (Proto) RegisterPeer

func (p Proto) RegisterPeer(peer *Peer) *Peer

RegisterPeer Регистрация пира в списках пиров

func (Proto) RequestPeers

func (p Proto) RequestPeers(peer *Peer)

RequestPeers Запрос списка пиров

func (Proto) SendMessage

func (p Proto) SendMessage(peer *Peer, msg string)

SendMessage Отправка сообщения

func (Proto) SendName

func (p Proto) SendName(peer *Peer)

SendName Отправка своего имени в сокет

func (Proto) SendPeers

func (p Proto) SendPeers(peer *Peer)

SendPeers Отправка списка пиров

func (Proto) String

func (p Proto) String() string

func (Proto) UnregisterPeer

func (p Proto) UnregisterPeer(peer *Peer)

UnregisterPeer Удаление пира из списка

type Serializable

type Serializable interface {
	ToJson() []byte
}

Serializable interface to detect that can to serialised to json

type SharedKey

type SharedKey struct {
	RemoteKey []byte
	LocalKey  []byte
	Secret    []byte
}

SharedKey ECDHE shared key

func (*SharedKey) Update

func (sk *SharedKey) Update(remoteKey []byte, localKey []byte)

Update shared key info

type WsCmd

type WsCmd struct {
	Cmd string `json:"cmd"`
}

WsCmd WebSocket command

type WsMessage

type WsMessage struct {
	WsCmd
	From    string `json:"from"`
	To      string `json:"to"`
	Content string `json:"content"`
}

WsMessage WebSocket command: new Message

func (WsMessage) ToJson

func (v WsMessage) ToJson() []byte

ToJson convert to JSON bytes

type WsMyName

type WsMyName struct {
	WsCmd
	Name   string `json:"name"`
	PubKey string `json:"id"`
}

WsMyName WebSocket command: PeerName

func (WsMyName) ToJson

func (v WsMyName) ToJson() []byte

ToJson convert to JSON bytes

type WsPeerList

type WsPeerList struct {
	WsCmd
	Peers []PeerName `json:"peers"`
}

WsPeerList WebSocket command: list of peers

func (WsPeerList) ToJson

func (v WsPeerList) ToJson() []byte

ToJson convert to JSON bytes

Jump to

Keyboard shortcuts

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