ciphrtxt

package
v0.0.0-...-686776b Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2017 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	WSDefaultMessageVersion = 0x0001

	WSRequestTypeTime         = 0x0001
	WSRequestTypeHeadersSince = 0x0002
	WSRequestTypeStatus       = 0x0003

	WSResponseTypeTime   = 0x0101
	WSResponseTypeHeader = 0x0102
	WSResponseTypeStatus = 0x0103
)
View Source
const (
	DefaultWatchdogTimeout = 150 * time.Second
	DefaultTimeTickle      = 30 * time.Second
	DefaultStatusTickle    = 300 * time.Second
	DefaultPeersTickle     = 300 * time.Second
)
View Source
const MessageHeaderLengthB64V2 = (256)

const MessageHeaderLengthB64V2 = ((MessageHeaderLengthV2 * 4) / 3)

View Source
const MessageHeaderLengthV1 = 5 + 1 +
	8 + 1 +
	8 + 1 +
	66 + 1 +
	66 + 1 +
	66 + 1 +
	64 + 1 +

	64 // s (256-bit integer, hex)
View Source
const MessageHeaderLengthV2 = (192)

const MessageHeaderLengthV2 = (ShortMessageHeaderLengthV2+32+32+5)

View Source
const ShardBaseVal = 0x0200
View Source
const ShardMaxVal = (ShardBaseVal + ShardNBins)
View Source
const ShardNBins = (1 << ShardSectorOuterRing)
View Source
const ShardSectorOuterRing = 9
View Source
const ShortMessageHeaderLengthB64V2 = (164)

const ShortMessageHeaderLengthB64V2 = ((ShortMessageHeaderLengthV2 * 4) / 3)

View Source
const ShortMessageHeaderLengthV2 = (123)

const ShortMessageHeaderLengthV2 = (4+4+4+33+33+33+4+8)

Variables

This section is empty.

Functions

func CheckOrCreateDirectory

func CheckOrCreateDirectory(filepath string) (err error)

Types

type BinaryMessageHeaderV2

type BinaryMessageHeaderV2 [MessageHeaderLengthV2]byte

type FullMessageHeader

type FullMessageHeader struct {
	I big.Int
	J big.Int
	K big.Int
	// contains filtered or unexported fields
}

func (*FullMessageHeader) Deserialize

func (z *FullMessageHeader) Deserialize(s string) error

func (*FullMessageHeader) ExpireTime

func (z *FullMessageHeader) ExpireTime() time.Time

func (*FullMessageHeader) ExportBytes

func (z *FullMessageHeader) ExportBytes() []byte

func (*FullMessageHeader) Hash

func (z *FullMessageHeader) Hash() []byte

func (*FullMessageHeader) IKey

func (z *FullMessageHeader) IKey() []byte

func (*FullMessageHeader) ImportBytes

func (z *FullMessageHeader) ImportBytes(b []byte) error

func (*FullMessageHeader) JKey

func (z *FullMessageHeader) JKey() []byte

func (*FullMessageHeader) KKey

func (z *FullMessageHeader) KKey() []byte

func (*FullMessageHeader) MessageTime

func (z *FullMessageHeader) MessageTime() time.Time

func (*FullMessageHeader) Serialize

func (z *FullMessageHeader) Serialize() string

type HeaderCache

type HeaderCache struct {
	Count         int
	NetworkErrors int
	PeerInfo      []PeerItemResponse
	// contains filtered or unexported fields
}

func OpenHeaderCache

func OpenHeaderCache(host string, port uint16, dbpath string) (hc *HeaderCache, err error)

func (*HeaderCache) Close

func (hc *HeaderCache) Close()

func (*HeaderCache) FindByI

func (hc *HeaderCache) FindByI(I []byte) (h MessageHeader, err error)

func (*HeaderCache) FindExpiringAfter

func (hc *HeaderCache) FindExpiringAfter(tstamp uint32) (hdrs []RawMessageHeader, err error)

func (*HeaderCache) FindSince

func (hc *HeaderCache) FindSince(tstamp uint32) (hdrs []RawMessageHeader, err error)

func (*HeaderCache) GetPeerStatsJSON

func (hc *HeaderCache) GetPeerStatsJSON() (stats *PeerJSON)

func (*HeaderCache) HandleWSDisconnect

func (hc *HeaderCache) HandleWSDisconnect()

func (*HeaderCache) HandleWSStatusResponse

func (hc *HeaderCache) HandleWSStatusResponse(message StatusResponse)

func (*HeaderCache) HandleWSTimeResponse

func (hc *HeaderCache) HandleWSTimeResponse(message int)

func (*HeaderCache) Insert

func (hc *HeaderCache) Insert(h MessageHeader) (insert bool, err error)

func (*HeaderCache) RefreshStatus

func (hc *HeaderCache) RefreshStatus() (status string)

func (*HeaderCache) Remove

func (hc *HeaderCache) Remove(h MessageHeader) (err error)

func (*HeaderCache) SetupWSHandler

func (hc *HeaderCache) SetupWSHandler(client cwebsocket.ClientConnection)

func (*HeaderCache) Sync

func (hc *HeaderCache) Sync() (err error)

func (*HeaderCache) UpdateTime

func (hc *HeaderCache) UpdateTime(serverTime uint32) (err error)

func (*HeaderCache) WebsocketWatchdog

func (hc *HeaderCache) WebsocketWatchdog()

type HeaderListResponse

type HeaderListResponse struct {
	Headers []string `json:"header_list"`
}

type LocalHeaderCache

type LocalHeaderCache struct {
	Count int
	Peers []*peerCache

	ExternalHost string
	ExternalPort int
	ExtTokenPort int
	PubKey       string
	// contains filtered or unexported fields
}

func OpenLocalHeaderCache

func OpenLocalHeaderCache(filepath string) (lhc *LocalHeaderCache, err error)

func (*LocalHeaderCache) AddPeer

func (lhc *LocalHeaderCache) AddPeer(host string, port uint16)

func (*LocalHeaderCache) Close

func (lhc *LocalHeaderCache) Close()

func (*LocalHeaderCache) ConnectWSPeer

func (lhc *LocalHeaderCache) ConnectWSPeer(con iwebsocket.Connection)

func (*LocalHeaderCache) DiscoverPeers

func (lhc *LocalHeaderCache) DiscoverPeers(exthost string, extport uint16) (err error)

func (*LocalHeaderCache) FindByI

func (lhc *LocalHeaderCache) FindByI(I []byte) (h *RawMessageHeader, err error)

func (*LocalHeaderCache) FindExpiringAfter

func (lhc *LocalHeaderCache) FindExpiringAfter(tstamp uint32) (hdrs []RawMessageHeader, err error)

func (*LocalHeaderCache) FindSince

func (lhc *LocalHeaderCache) FindSince(tstamp uint32) (hdrs []RawMessageHeader, err error)

func (*LocalHeaderCache) Insert

func (lhc *LocalHeaderCache) Insert(h MessageHeader) (insert bool, err error)

func (*LocalHeaderCache) ListPeers

func (lhc *LocalHeaderCache) ListPeers() (plr []PeerItemResponse)

func (*LocalHeaderCache) RefreshStatus

func (lhc *LocalHeaderCache) RefreshStatus() (status string)

func (*LocalHeaderCache) Remove

func (lhc *LocalHeaderCache) Remove(h MessageHeader) (err error)

func (*LocalHeaderCache) Status

func (lhc *LocalHeaderCache) Status() (status *StatusResponse)

func (*LocalHeaderCache) Sync

func (lhc *LocalHeaderCache) Sync() (err error)

type MessageFile

type MessageFile struct {
	RawMessageHeader
	Size       uint64
	Servertime uint32
	Filepath   string
}

func Ingest

func Ingest(filepath string) *MessageFile

func (*MessageFile) Deserialize

func (z *MessageFile) Deserialize(bmh []byte) *MessageFile

func (*MessageFile) Move

func (z *MessageFile) Move(filepath string) error

func (*MessageFile) Serialize

func (z *MessageFile) Serialize() []byte

type MessageFileSlice

type MessageFileSlice []MessageFile

func (MessageFileSlice) Len

func (z MessageFileSlice) Len() int

func (MessageFileSlice) Less

func (z MessageFileSlice) Less(i, j int) bool

func (MessageFileSlice) Swap

func (z MessageFileSlice) Swap(i, j int)

type MessageHeader

type MessageHeader interface {
	Serialize() string
	ExportBytes() []byte
	Deserialize(string) error
	ImportBytes([]byte) error
	MessageTime() time.Time
	ExpireTime() time.Time
	IKey() []byte
	JKey() []byte
	KKey() []byte
	Hash() []byte
	// contains filtered or unexported methods
}

type MessageHeaderJSON

type MessageHeaderJSON struct {
	Version   string `json:"version"`
	Time      uint32 `json:"time"`
	Expire    uint32 `json:"expire"`
	TimeStr   string `json:"time_str"`
	ExpireStr string `json:"expire_str"`
	I         string `json:"I"`
	J         string `json:"J"`
	K         string `json:"K"`
	Size      uint64 `json:"Size"`
	R         string `json:"sig_r"`
	S         string `json:"sig_s"`
	Nonce     uint64 `json:"nonce"`
}

type MessageListResponse

type MessageListResponse struct {
	Messages []string `json:"message_list"`
}

type MessageStore

type MessageStore struct {
	Count int

	LHC          *LocalHeaderCache
	ExternalHost string
	ExternalPort int
	ExtTokenPort int
	PubKey       string
	// contains filtered or unexported fields
}

func OpenMessageStore

func OpenMessageStore(filepath string, lhc *LocalHeaderCache, startbin int) (ms *MessageStore, err error)

func (*MessageStore) Close

func (ms *MessageStore) Close()

func (*MessageStore) FindByI

func (ms *MessageStore) FindByI(I []byte) (m *MessageFile, err error)

func (*MessageStore) FindOrFetchByI

func (ms *MessageStore) FindOrFetchByI(I []byte) (m *MessageFile, err error)

func (*MessageStore) FindSince

func (ms *MessageStore) FindSince(tstamp uint32) (msgs []MessageFile, err error)

func (*MessageStore) GetCurrentTarget

func (ms *MessageStore) GetCurrentTarget() (target ShardSector)

func (*MessageStore) Insert

func (ms *MessageStore) Insert(m *MessageFile) (servertime uint32, err error)

func (*MessageStore) InsertFile

func (ms *MessageStore) InsertFile(filepath string) (servertime uint32, err error)

func (*MessageStore) RefreshStatus

func (ms *MessageStore) RefreshStatus() (status string)

func (*MessageStore) Remove

func (ms *MessageStore) Remove(m *MessageFile) (err error)

func (*MessageStore) SetTarget

func (ms *MessageStore) SetTarget(target ShardSector)

func (*MessageStore) Status

func (ms *MessageStore) Status() (status *StatusResponse)

func (*MessageStore) Sync

func (ms *MessageStore) Sync() (err error)

type MessageUploadResponse

type MessageUploadResponse struct {
	Header     string `json:"header"`
	Servertime uint32 `json:"servertime"`
}

type PeerItemResponse

type PeerItemResponse struct {
	Host string `json:"host"`
	Port uint16 `json:"port"`
}

type PeerJSON

type PeerJSON struct {
	Host     string `json:"host"`
	Port     uint16 `json:"port"`
	URL      string `json:"url"`
	Headers  int    `json:"headers"`
	Messages int    `json:"messages"`
	Start    int    `json:"start"`
	Ring     int    `json:"ring"`
}

type RawMessageHeader

type RawMessageHeader struct {
	I []byte
	J []byte
	K []byte
	// contains filtered or unexported fields
}

func ImportBinaryHeaderV2

func ImportBinaryHeaderV2(smh []byte) *RawMessageHeader

func (*RawMessageHeader) Deserialize

func (z *RawMessageHeader) Deserialize(s string) error

func (*RawMessageHeader) ExpireTime

func (z *RawMessageHeader) ExpireTime() time.Time

func (*RawMessageHeader) ExportBinaryHeaderV2

func (z *RawMessageHeader) ExportBinaryHeaderV2() *BinaryMessageHeaderV2

func (*RawMessageHeader) ExportBytes

func (z *RawMessageHeader) ExportBytes() []byte

func (*RawMessageHeader) Hash

func (z *RawMessageHeader) Hash() []byte

func (*RawMessageHeader) IKey

func (z *RawMessageHeader) IKey() (k []byte)

func (*RawMessageHeader) ImportBytes

func (z *RawMessageHeader) ImportBytes(b []byte) error

func (*RawMessageHeader) JKey

func (z *RawMessageHeader) JKey() (k []byte)

func (*RawMessageHeader) JSON

func (*RawMessageHeader) KKey

func (z *RawMessageHeader) KKey() (k []byte)

func (*RawMessageHeader) MessageTime

func (z *RawMessageHeader) MessageTime() time.Time

func (*RawMessageHeader) Serialize

func (z *RawMessageHeader) Serialize() string

func (*RawMessageHeader) SerializeV1

func (z *RawMessageHeader) SerializeV1() *SerializedMessageHeaderV1

func (*RawMessageHeader) SerializeV2

func (z *RawMessageHeader) SerializeV2() *SerializedMessageHeaderV2

type RawMessageHeaderSlice

type RawMessageHeaderSlice []RawMessageHeader

func (RawMessageHeaderSlice) Len

func (z RawMessageHeaderSlice) Len() int

func (RawMessageHeaderSlice) Less

func (z RawMessageHeaderSlice) Less(i, j int) bool

func (RawMessageHeaderSlice) Swap

func (z RawMessageHeaderSlice) Swap(i, j int)

type SerializedMessageHeaderV1

type SerializedMessageHeaderV1 [MessageHeaderLengthV1]byte

type SerializedMessageHeaderV2

type SerializedMessageHeaderV2 [MessageHeaderLengthB64V2]byte

type ShardSector

type ShardSector struct {
	Start int  `json:"start"`
	Ring  uint `json:"ring"`
}

func (*ShardSector) Contains

func (s *ShardSector) Contains(I []byte) (c bool)

type StatusNetworkResponse

type StatusNetworkResponse struct {
	Host    string `json:"host"`
	MSGPort int    `json:"message_service_port"`
	TOKPort int    `json:"token_service_port"`
}

type StatusResponse

type StatusResponse struct {
	Network StatusNetworkResponse `json:"network"`
	Pubkey  string                `json:"pubkey"`
	Sector  ShardSector           `json:"sector"`
	Storage StatusStorageResponse `json:"storage"`
	Version string                `json:"version"`
}

type StatusStorageResponse

type StatusStorageResponse struct {
	Capacity    int `json:"capacity"`
	Headers     int `json:"headers"`
	Maxfilesize int `json:"max_file_size"`
	Messages    int `json:"messages"`
	Used        int `json:"used"`
}

type TimeRequest

type TimeRequest struct {
	RequestType uint32 `json:"request_type"`
}

type TimeResponse

type TimeResponse struct {
	Time int `json:"time"`
}

type WSDisconnectFunc

type WSDisconnectFunc func()

type WSMessage

type WSMessage struct {
	Ver     uint16
	Type    uint16
	DataLen uint64

	Data []byte
	// contains filtered or unexported fields
}

WSMessage implements the ciphrtxt websocket wire protocol. All requests and responses are encoded/decoded via this package.

func DeserializeWSMessage

func DeserializeWSMessage(raw []byte) (wsm *WSMessage, err error)

func NewWSMessageHeaderResponse

func NewWSMessageHeaderResponse(hdr MessageHeader) (wsm *WSMessage)

func NewWSMessageHeadersSinceRequest

func NewWSMessageHeadersSinceRequest(unixtime uint32) (wsm *WSMessage)

func NewWSMessageStatusRequest

func NewWSMessageStatusRequest() (wsm *WSMessage)

func NewWSMessageStatusResponse

func NewWSMessageStatusResponse(sr *StatusResponse) (wsm *WSMessage)

func NewWSMessageTimeRequest

func NewWSMessageTimeRequest() (wsm *WSMessage)

func NewWSMessageTimeResponse

func NewWSMessageTimeResponse() (wsm *WSMessage)

func (*WSMessage) DumpMessageHeader

func (wsm *WSMessage) DumpMessageHeader() (rmh *RawMessageHeader)

func (*WSMessage) SerializeMessage

func (wsm *WSMessage) SerializeMessage() (msgbytes []byte)

type WSProtocolHandler

type WSProtocolHandler interface {
	TxHeader(rmh MessageHeader)
	OnDisconnect(f WSDisconnectFunc)
	Disconnect()
	Status() *StatusResponse
	RequestStatus()
	AdoptRemote(rhc *HeaderCache)
}

Jump to

Keyboard shortcuts

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