Documentation ¶
Overview ¶
Package proto - Core of p2p protocol
Index ¶
- func CalcSharedSecret(publicKey []byte, privateKey []byte) (secret [32]byte)
- func CreateKeyExchangePair() (publicKey [32]byte, privateKey [32]byte)
- func Decrypt(encrypted []byte, key []byte) []byte
- func Encrypt(content []byte, key []byte) []byte
- func LoadKey(name string) (publicKey ed25519.PublicKey, privateKey ed25519.PrivateKey)
- func SaveKey(fileName string) *os.File
- type Envelope
- type HandShake
- type Peer
- type PeerName
- type Peers
- type Proto
- func (p Proto) HandleProto(rw *bufio.ReadWriter, peer *Peer)
- func (p Proto) ListenPeer(peer *Peer)
- func (p Proto) MyName() *PeerName
- func (p Proto) RegisterPeer(peer *Peer) *Peer
- func (p Proto) RequestPeers(peer *Peer)
- func (p Proto) SendMessage(peer *Peer, msg string)
- func (p Proto) SendName(peer *Peer)
- func (p Proto) SendPeers(peer *Peer)
- func (p Proto) String() string
- func (p Proto) UnregisterPeer(peer *Peer)
- type Serializable
- type SharedKey
- type WsCmd
- type WsMessage
- type WsMyName
- type WsPeerList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalcSharedSecret ¶
CalcSharedSecret Calculate shared secret
func CreateKeyExchangePair ¶
CreateKeyExchangePair create pair for ECDHE
Types ¶
type Envelope ¶
type Envelope struct { Cmd []byte Id []byte From []byte To []byte Sign []byte Length uint16 Content []byte }
Envelope Конверт для сообщений между пирами
func NewEnvelope ¶
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 ¶
ReadEnvelope Формирование конверта из байтов ридера сокета
func UnSerialize ¶
UnSerialize Десериализация массива байт в конверт с содержимым
type HandShake ¶
type HandShake struct { Name string `json:"name"` PubKey string `json:"id"` ExKey string `json:"exKey"` }
HandShake type for handshake on connection
type Peer ¶
type Peer struct { PubKey ed25519.PublicKey Conn *net.Conn Name string FirstSeen string LastSeen string Peers *Peers }
Peer basic struct to describe peer
func (*Peer) UpdatePeer ¶
UpdatePeer Update peer struct after handshake
type Proto ¶
type Proto struct { Port int Name string Peers *Peers PubKey ed25519.PublicKey Broker chan *Envelope // contains filtered or unexported fields }
Proto Ядро протокола
func (Proto) HandleProto ¶
func (p Proto) HandleProto(rw *bufio.ReadWriter, peer *Peer)
HandleProto Обработка входящих сообщений
func (Proto) ListenPeer ¶
ListenPeer Старт прослушивания соединения с пиром
func (Proto) RegisterPeer ¶
RegisterPeer Регистрация пира в списках пиров
func (Proto) RequestPeers ¶
RequestPeers Запрос списка пиров
func (Proto) SendMessage ¶
SendMessage Отправка сообщения
func (Proto) UnregisterPeer ¶
UnregisterPeer Удаление пира из списка
type Serializable ¶
type Serializable interface {
ToJson() []byte
}
Serializable interface to detect that can to serialised to json
type WsMessage ¶
type WsMessage struct { WsCmd From string `json:"from"` To string `json:"to"` Content string `json:"content"` }
WsMessage WebSocket command: new Message
type WsPeerList ¶
WsPeerList WebSocket command: list of peers