protocol

package
v0.0.0-...-f3f2e11 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2017 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package protocol - this package is the application protocol for the application and service.

Index

Constants

This section is empty.

Variables

View Source
var RequestMethodToString = map[RequestMethod]string{
	GetFileMethod:          "GetFile",
	PostFileMethod:         "PostFile",
	GetPublicKeyMethod:     "GetPublicKey",
	PostPublicKeyMethod:    "PostPublicKey",
	DeleteFileMethod:       "DeleteFile",
	GetSuccessorMethod:     "GetSuccessor",
	SetPredecessorMethod:   "SetPredecessor",
	GetPredecessorMethod:   "GetPredecessor",
	GetFingerTableMethod:   "GetFingerTable",
	UserRegistrationMethod: "UserRegistrationMethod",
	NodeRegistrationMethod: "NodeRegistrationMethod",
	NodeTrustMethod:        "NodeTrustMethod",
}

RequestMethodToString - Convert from a Request Method to String

View Source
var (
	// ValidResponseStatus - Used for verification that a response is right
	ValidResponseStatus = map[ResponseStatus]bool{
		Success: true, Error: true,
	}
)

Functions

This section is empty.

Types

type CallerType

type CallerType uint8
const (
	UserType CallerType = iota
	NodeType
)

type EncryptedMessage

type EncryptedMessage struct {
	Header     Header
	SessionKey []byte
	IV         []byte
	CipherText []byte
}

EncryptedMessage - this will be the "wrapper" to add encryption to the messages. The transport will pack the existing request/response into this encrypted message

func (*EncryptedMessage) Validate

func (em *EncryptedMessage) Validate() error

Validate - Implement validate for the header validation

type Handler

type Handler = func(ctx context.Context, r *Request) Response

Handler - This is what a server handler signature should be

type Header struct {
	Key          models.Identifier
	From         models.Identifier
	FromAddr     string
	Type         CallerType
	PubKey       *rsa.PublicKey
	SignedBy     models.Identifier
	Signature    []byte
	DataLength   uint64
	ResourceName string
	Log          bool
	Clock        uint64
	Secret       []byte
	SharedWith   []SharedSecret
}

Header - protocol header, used in every message, contains the peerstore version, the key (if applicable), from and to nodes and the length of the data in the data section of the message.

func (*Header) Validate

func (h *Header) Validate() error

Validate - Implement validate for the header validation

type NodeRegistrationResponse

type NodeRegistrationResponse struct {
	Signature []byte
	SignedBy  models.Identifier
	Nodes     []models.Node
}

type Request

type Request struct {
	Header Header
	Method RequestMethod
	Data   []byte
}

Request - the standard request, includes a header, method and data. The resource is defined in the header and the data length is defined in the header as well.

func (*Request) Validate

func (r *Request) Validate() error

Validate - implementation of Validatable, makes sure the request is a valid request

type RequestMethod

type RequestMethod uint64

RequestMethod - this is the indication of what request is to be performed.

const (
	// GetFileMethod - Get File Method to be used when getting files
	GetFileMethod RequestMethod = 1 << iota
	// PostFileMethod - Post File Method to be used when inserting or updating
	PostFileMethod
	// DeleteFileMethod - Delete File Method to be used when deleting files
	DeleteFileMethod
	// GetSuccessorMethod - Chord Method to get the successor
	GetSuccessorMethod
	// SetPredecessorMethod - Chord Method to set the predecessor
	SetPredecessorMethod
	// GetPredecessorMethod - Chord Method to get the predecessor
	GetPredecessorMethod
	// GetFingerTableMethod - Chord Method to get the finger table
	GetFingerTableMethod
	// UserRegistrationMethod - user registration methos
	UserRegistrationMethod
	// NodeRegistrationMethod - user registration methos
	NodeRegistrationMethod
	// NodeTrustMethod - user registration methos
	NodeTrustMethod
	GetPublicKeyMethod
	PostPublicKeyMethod
)

type Response

type Response struct {
	Header Header
	Status ResponseStatus
	Data   []byte
}

Response - the response structure for any given request

func (*Response) Validate

func (r *Response) Validate() error

Validate - implementation of Validatable, makes sure the response is a valid response

type ResponseStatus

type ResponseStatus int64

ResponseStatus - the type which indicates the response status for a request

const (
	// Success - the message request was successful
	Success ResponseStatus = 1 << iota
	// Error - the message request was not successful
	Error
)

type RoundTripper

type RoundTripper interface {
	RoundTrip(*Request) (Response, error)
}

RoundTripper - interface which will perform the request, and return the Response

type Server

type Server struct {
	PrivateKey *rsa.PrivateKey
	// contains filtered or unexported fields
}

Server - base server type, contains a listener to listen for sockets

func NewServer

func NewServer(key *rsa.PrivateKey, peer models.Node, address, dataPath string, bufferSize, numWorkers uint) (*Server, error)

NewServer - create a new server

func (*Server) Handle

func (s *Server) Handle(method RequestMethod, fn Handler)

Handle - add handlers to the server

func (*Server) NodeRegistrationHandler

func (s *Server) NodeRegistrationHandler(ctx context.Context, r *Request) Response

NodeRegistrationHandler - this handler handles all node registrations. A node registration consists of the node giving the server it's public key, and the server signing that key, and returning the signed key as well as a list of other nodes with coreseponding public keys that it knows about

func (*Server) NodeTrustHandler

func (s *Server) NodeTrustHandler(ctx context.Context, r *Request) Response

NodeTrustHandler - this handler handles all node trust requests. A node registration consists of the node giving the server it's public key, and the server signing that key, and returning the signed key as well as a list of other nodes with coreseponding public keys that it knows about

func (*Server) Serve

func (s *Server) Serve(q chan bool, done chan bool)

Serve - process to serve requests, for each request that we accept as a connection, we will fork the handling of that connection.

func (*Server) UserRegistrationHandler

func (s *Server) UserRegistrationHandler(ctx context.Context, r *Request) Response

UserRegistrationHandler - this handler handles all user registrations. A user registration consists of the user giving the server it's public key, and the server will place that public key in the DHT for future validations

type SharedSecret

type SharedSecret struct {
	ID     models.Identifier
	Secret []byte
}

type Transport

type Transport struct {
	Type CallerType
	// contains filtered or unexported fields
}

Transport - a transport structure that will implement RoundTripper transport will also handle all encryption/decryption of the messages

func NewTransport

func NewTransport(proto, addr string, t CallerType, id models.Identifier, peerKey *rsa.PublicKey, selfKey *rsa.PrivateKey) (*Transport, error)

NewTransport - create a new transport structure

func (*Transport) Close

func (t *Transport) Close()

Close - close the connection transport

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(request *Request) (Response, error)

RoundTrip - Implementation of a round tripper interface, effectively this is how the request will be serialized, and put on the wire, and how the response will be deserialized

Jump to

Keyboard shortcuts

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