common

package
v0.0.0-...-52bbd4c Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2019 License: GPL-3.0 Imports: 18 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// P2PProtocolName will be used by libp2p streams
	P2PProtocolName = "ipfsShareP2P"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AddressBook

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

AddressBook is a cache for fellow users' P2P contact data

func NewAddressBook

func NewAddressBook(backend chequebook.Backend, app *ethapp.FileTribeDApp, ipfs ipfs.IIpfs) *AddressBook

NewAddressBook creates a new AddressBook

func (*AddressBook) Get

func (a *AddressBook) Get(accAddr ethcommon.Address) (*Contact, error)

Get tries to retrieve the P2P contact data of a user

type Contact

type Contact struct {
	AccountAddress    ethcommon.Address
	EthAccountAddress ethcommon.Address
	Name              string
	IpfsPeerID        string
	Boxer             tribecrypto.AnonymPublicKey
	// contains filtered or unexported fields
}

Contact stores necessary information for P2P communication with a user

func NewContact

func NewContact(
	address ethcommon.Address,
	accAddr ethcommon.Address,
	name string,
	ipfsPeerID string,
	boxer tribecrypto.AnonymPublicKey,
	ipfs ipfs.IIpfs) *Contact

NewContact creates a new contact

func (*Contact) Send

func (contact *Contact) Send(data []byte) error

Send sends a message to the given contact

func (*Contact) VerifySignature

func (contact *Contact) VerifySignature(digest, signature []byte) bool

VerifySignature verifies a signature if it really was made by the user this contact is representing

type GroupData

type GroupData byte

GroupData is an enumeration of which group data wants to be retrieved by peers

const (
	// GetGroupKey ...
	GetGroupKey GroupData = 0
	// GetProposedGroupKey ...
	GetProposedGroupKey GroupData = 1
)

type GroupDataMessage

type GroupDataMessage struct {
	Group   ethcommon.Address `json:"group"`
	Data    GroupData         `json:"data"`
	Payload []byte
}

GroupDataMessage is a wrapper for transferring group data like current key, a proposed key

func DecodeGroupDataMessage

func DecodeGroupDataMessage(data []byte) (*GroupDataMessage, error)

DecodeGroupDataMessage decodes a group message data

func (*GroupDataMessage) Encode

func (m *GroupDataMessage) Encode() ([]byte, error)

Encode encodes the group data message

type HeartBeat

type HeartBeat struct {
	From string `json:"from"`
	Rand []byte `json:"rand"`
}

HeartBeat is a heartbeat message, currently not used

type Message

type Message struct {
	From      ethcommon.Address `json:"from"`
	Type      MessageType       `json:"type"`
	SessionID uint32            `json:"session_id"`
	Payload   []byte            `json:"payload"`
	Sig       []byte            `json:"sig"`
}

Message is a message struct

func DecodeMessage

func DecodeMessage(data []byte) (*Message, error)

DecodeMessage decodes a message byte stream

func NewMessage

func NewMessage(from ethcommon.Address, msgType MessageType, sessionID uint32, payload []byte, signer Signer) (*Message, error)

NewMessage creates a new message

func (*Message) Digest

func (m *Message) Digest() []byte

Digest returns the message digest

func (*Message) Encode

func (m *Message) Encode() ([]byte, error)

Encode encodes the message

func (*Message) Verify

func (m *Message) Verify(contact *Contact) error

Verify verifies a message if it really originates from the sender

type MessageType

type MessageType byte

MessageType is an enumeration of message types

const (
	// GetGroupData enum value
	GetGroupData MessageType = 0
)

type P2PConn

type P2PConn net.TCPConn

P2PConn is tcp connection to an IPFS p2p dial/stream endpoint

func (*P2PConn) ReadMessage

func (conn *P2PConn) ReadMessage(addressBook *AddressBook) (*Message, error)

ReadMessage reads a message from the connection socket

type Signer

type Signer func(hash []byte) ([]byte, error)

Signer is a function which signs a hash

Jump to

Keyboard shortcuts

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