network

package
v0.0.0-...-d1fccd7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2019 License: GPL-3.0 Imports: 8 Imported by: 7

Documentation

Index

Constants

View Source
const (
	// BlobDataSize represents size of data in blob
	BlobDataSize = 1024 * 64
	// BlobRealDataSize represents real data in blob
	BlobRealDataSize = BlobDataSize - ed25519.PublicKeySize - 8 - 4
	// NumBlobs represents number of packets in Packets struct
	NumBlobs = NumPackets * packetDataSize / BlobDataSize

	// DataOffset identifies where blob data starts in blob.Data[] array
	DataOffset = flagsOffset + 4
)
View Source
const (
	// TransactionAddrServer is an address for transaction socket
	TransactionAddrServer = "0.0.0.0:40051"
	// BlockAddrServer is an address for incoming blocks
	BlockAddrServer = "127.0.0.1:40052"
	// MessagingAddrServer is an address for messaging socket
	MessagingAddrServer = "0.0.0.0:40057"
)
View Source
const (
	NumCoded   = 20
	MaxMissing = 4
	NumData    = NumCoded - MaxMissing
)
View Source
const FrameSize = 2 * 1024

FrameSize represents blob count in frame

View Source
const (

	// NumPackets represents number of packets in Packets struct
	NumPackets = 1024 * 8
)

Variables

View Source
var BlockAddrUserUDP = net.UDPAddr{
	Port: 50053,
	IP:   net.ParseIP("127.0.0.1"),
}

BlockAddrUserUDP is UDP address for Block transfering

Functions

func AddCodingBlobs2

func AddCodingBlobs2(blobs *Blobs, start int)

func BlobGenerator

func BlobGenerator(reader net.PacketConn, capacity int) <-chan *Blobs

BlobGenerator thread is responsible for reading blobs from socket and sending to the output channel

func BlobSender

func BlobSender(writer net.PacketConn, input <-chan *Blobs)

BlobSender thread is responsible for getting blobs from input channel and sending to the socket

func DecodeRS

func DecodeRS(frame []*Blob, start, end uint64) error

DecodeRS receives frame and recovers damaged data for efficiency it recovers only data, if coded blobs are demaged they will not be recovered

func DecodeRSBlock

func DecodeRSBlock(coding [][]byte, data [][]byte) error

DecodeRSBlock receives data and coding blocks. Recovers data from coding blocks Damaged data or coding block should be set to zero-length or nil Data and Coding must contain slices or else data will be copied and recovered at another memory address After recovery data is verified. The unsuccessful recovery causes error.

func EncodeRS

func EncodeRS(frame []*Blob, start, numBlobs uint64) error

EncodeRS generates coding blocks from frame

func EncodeRSBlock

func EncodeRSBlock(coding [][]byte, data [][]byte) error

EncodeRSBlock generates Reed-Solomon codes and writes to coding array coding and data elements must all be the same size

func FrameGenerator

func FrameGenerator(frame *Frame, input <-chan *Blobs) (chan *Blobs, chan []uint64)

FrameGenerator thread is responsible for generating recovered chunks of blobs form the Frame. Other nodes send Encoded blobs, so we have to make sure blobs can be decoded properly.

func PacketGenerator

func PacketGenerator(reader net.PacketConn, capacity int) <-chan *Packets

PacketGenerator thread is responsible for reading packets from socket and sending to the output channel

Types

type Blob

type Blob struct {
	Data [BlobDataSize]byte
	Addr net.Addr //UDP Address
	Size uint32
}

Blob stores block data Note: for now blob is just the copy of the Packet type with the exception of the byte array size

func AddCodingBlobs

func AddCodingBlobs(blobs []*Blob, start int) []*Blob

AddCodingBlobs adds dummy blobs for parity codes

func (*Blob) Flags

func (b *Blob) Flags() uint32

Flags method gets flags from blob

func (*Blob) From

func (b *Blob) From() ed25519.PublicKey

From method gets PublicKey from blob

func (*Blob) Index

func (b *Blob) Index() uint64

Index method gets index from Data array

func (*Blob) IsCoding

func (b *Blob) IsCoding() bool

IsCoding returns true if blob's coding flag is set

func (*Blob) SetCoding

func (b *Blob) SetCoding()

SetCoding sets blob's coding flag

func (*Blob) SetFlags

func (b *Blob) SetFlags(flags uint32)

SetFlags method sets flags to blob

func (*Blob) SetFrom

func (b *Blob) SetFrom(from ed25519.PublicKey)

SetFrom method sets PublicKey to blob

func (*Blob) SetIndex

func (b *Blob) SetIndex(index uint64)

SetIndex method sets blob index in front of Data array

type Blobs

type Blobs struct {
	Bs []Blob
}

Blobs stores slice of Blobs

func NewBlobs

func NewBlobs() *Blobs

NewBlobs returns Packets object

func NewNumBlobs

func NewNumBlobs(num uint64) *Blobs

NewNumBlobs returns Packets object with num packets

func (*Blobs) IndexBlobs

func (bs *Blobs) IndexBlobs(from ed25519.PublicKey, startIndex uint64)

IndexBlobs method will index blobs and set From

func (*Blobs) ReadFrom

func (bs *Blobs) ReadFrom(reader net.PacketConn) int

ReadFrom reads from the UDP socket and return number of bytes read.

func (*Blobs) WriteTo

func (bs *Blobs) WriteTo(writer net.PacketConn) int

WriteTo writes all blobs into the socket

type Frame

type Frame struct {
	Blobs []*Blob
}

Frame struct saves blobs. We use it to encode and decode blobs

func NewFrame

func NewFrame() *Frame

NewFrame returns brand new frame with empty blobs

type PCon

type PCon struct {
	B []byte
}

PCon mock

func (*PCon) Close

func (p *PCon) Close() error

Close implements the PacketConn Close mock method.

func (*PCon) LocalAddr

func (p *PCon) LocalAddr() net.Addr

LocalAddr implements the PacketConn LocalAddr mock method.

func (*PCon) ReadFrom

func (p *PCon) ReadFrom(b []byte) (n int, addr net.Addr, err error)

ReadFrom implements the PacketConn ReadFrom mock method.

func (*PCon) SetDeadline

func (p *PCon) SetDeadline(t time.Time) error

SetDeadline implements the PacketConn SetDeadline mock method.

func (*PCon) SetReadDeadline

func (p *PCon) SetReadDeadline(t time.Time) error

SetReadDeadline implements the PacketConn SetReadDeadline mock method.

func (*PCon) SetWriteDeadline

func (p *PCon) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the PacketConn SetWriteDeadline mock method.

func (*PCon) WriteTo

func (p *PCon) WriteTo(b []byte, addr net.Addr) (n int, err error)

WriteTo implements the PacketConn WriteTo mock method.

type Packet

type Packet struct {
	Data [packetDataSize]byte
	Size uint8
	Addr net.Addr //UDP Address
	// contains filtered or unexported fields
}

Packet stores transaction data

type Packets

type Packets struct {
	Ps []Packet
}

Packets stores slice of packets

func NewNumPackets

func NewNumPackets(num uint64) *Packets

NewNumPackets returns Packets object with num packets

func NewPackets

func NewPackets() *Packets

NewPackets returns Packets object

func PacketBatch

func PacketBatch(input <-chan *Packets) []*Packets

PacketBatch is responsible for reading packets from channel and sending batches of packets to the output maximum batch size should be maxBatchSize packets PacketBatch waits for 1 second for the incoming packets

func (*Packets) ReadFrom

func (ps *Packets) ReadFrom(reader net.PacketConn) int

ReadFrom reads from the UDP socket and return number of bytes read.

func (*Packets) WriteTo

func (ps *Packets) WriteTo(writer net.PacketConn) int

WriteTo writes all packets into the socket

type SocketMock

type SocketMock struct {
	Addr net.Addr
	// contains filtered or unexported fields
}

SocketMock is socket connection mock for testing

func NewSocketMock

func NewSocketMock(readError error, writeError error, addr net.Addr) *SocketMock

func (*SocketMock) AddToReadBuff

func (conn *SocketMock) AddToReadBuff(b []byte)

func (*SocketMock) Close

func (conn *SocketMock) Close() error

Close implements the PacketConn Close mock method.

func (*SocketMock) EmptyWriteBuff

func (conn *SocketMock) EmptyWriteBuff() []byte

func (*SocketMock) LocalAddr

func (conn *SocketMock) LocalAddr() net.Addr

LocalAddr implements the PacketConn LocalAddr mock method.

func (*SocketMock) ReadBuffSize

func (conn *SocketMock) ReadBuffSize() int

func (*SocketMock) ReadFrom

func (conn *SocketMock) ReadFrom(b []byte) (n int, addr net.Addr, err error)

ReadFrom implements the PacketConn ReadFrom mock method.

func (*SocketMock) SetDeadline

func (conn *SocketMock) SetDeadline(t time.Time) error

SetDeadline implements the PacketConn SetDeadline mock method.

func (*SocketMock) SetReadDeadline

func (conn *SocketMock) SetReadDeadline(t time.Time) error

SetReadDeadline implements the PacketConn SetReadDeadline mock method.

func (*SocketMock) SetWriteDeadline

func (conn *SocketMock) SetWriteDeadline(t time.Time) error

SetWriteDeadline implements the PacketConn SetWriteDeadline mock method.

func (*SocketMock) WriteBuffSize

func (conn *SocketMock) WriteBuffSize() int

func (*SocketMock) WriteTo

func (conn *SocketMock) WriteTo(b []byte, addr net.Addr) (n int, err error)

WriteTo implements the PacketConn WriteTo mock method.

Jump to

Keyboard shortcuts

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