handlers

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2015 License: BSD-2-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxPostSize maximum size for posts
	MaxPostSize = 96000
	// MinPostSize for posts
	MinPostSize = (message.SignHeaderSize + message.KeyHeaderSize + 1) * 4
	// MinHashCashBits minimum hashcash bits
	MinHashCashBits = 24
	// DefaultMaxSleep is the maximum pause per sleep (info / post handlers)
	DefaultMaxSleep = int64(time.Second) * 3 / 2
	// DefaultIndexGlobal is the maximum number of entries to fetch from the global index per call
	DefaultIndexGlobal = 1000
	// DefaultIndexKey is the maximum number of entries to fetch from a key, per call
	DefaultIndexKey = 23
	// DefaultTimeGrace is the grace time given for authentication
	DefaultTimeGrace = uint64(60)
	// DefaultAuthTokenAge is the maximum age a keyproof token may have
	DefaultAuthTokenAge = 3600 * 3
	// DefaultNotifyDuration is the time to wait between notification sends
	DefaultNotifyDuration = 600 // every 10min
	// DefaultFetchDuration is the time between fetch attempts
	DefaultFetchDuration = 600 // every 10min
	// DefaultFetchMax is the number of messages to fetch from a peer per call
	DefaultFetchMax = 30
	// DefaultListenPort is the port on which to listen for HTTP connections
	DefaultListenPort = 8080
	// DefaultStepLimit is the extra number of bits to overcome for boost to apply in hashcash limits calculation
	DefaultStepLimit = 2
	// DefaultExpireDuration is the time between expire runs
	DefaultExpireDuration = 3600
	// DefaultExpireFSDuration is the time between filesystem expire runs
	DefaultExpireFSDuration = 86400 // once a day. Should be infrequent since it is expensive
	// DefaultMaxTimeSkew is the maximum time skew to allow and use
	DefaultMaxTimeSkew = 86400
	// DefaultMinStoreTime is the minimum time to store a message, in seconds
	DefaultMinStoreTime = 7200
	// DefaultMaxStoreTime is the maximum time to ever store a message, in seconds
	DefaultMaxStoreTime = 2592000
	// DefaultAddToPeer determines if the server adds itself to the peerlist
	DefaultAddToPeer = true
)
View Source
const Version = "0.0.1 very alpha"

Version of this release

Variables

View Source
var (
	// ErrBadMessageID .
	ErrBadMessageID = errors.New("server: MessageID unexpected")
)
View Source
var Workers = 100

Workers defines how many parallel index access goroutines may exist without locking

Functions

This section is empty.

Types

type MessageServer

type MessageServer struct {
	DB *messagestore.Store

	URL             string // my own URL
	AddToPeer       bool   // if to add oneself to the peerlist
	MaxPostSize     int64  // Maximum post size
	MinPostSize     int    //Minimum post size
	MinHashCashBits byte   // Minimum hashcash bits required
	MaxTimeSkew     int64  // Maximum timeskew to use and allow

	TokenPrivKey         *[ed25519.PrivateKeySize]byte
	AuthPubKey           *message.Curve25519Key       // Used for hidden key index access
	TokenPubKey          *[ed25519.PublicKeySize]byte // Used for peer identification
	InfoStruct           *ServerInfo
	TimeSkew             int64  // TimeSkew changes the returned time by a constant
	TimeGrace            uint64 // Grace time for authentication
	MaxSleep             int64  // MaxSleep is the maximum number of nano seconds of a sleep call
	MaxIndexGlobal       int64  // Maximum entries from global index
	MaxIndexKey          int64  // Maximum entries from key index
	MaxAuthTokenAge      int64  // Maximum age of peer authentication token
	PeerFile             string // File containing the peer information
	NotifyDuration       int64  // Time between notifications
	FetchDuration        int64  // Time between fetches
	FetchMax             int    // Maximum messages to fetch per call to peer
	ExpireDuration       int64  // Time between expire runs
	ExpireFSDuration     int64  // Time between filesystem expire runs
	SocksProxy           string // Socks5 proxy
	EnableDeleteHandler  bool   // should the delete handler be enabled?
	EnableOneTimeHandler bool   // should the one-time message handler be enabled?
	EnablePeerHandler    bool   // show the peer handler be offered?
	HubOnly              bool   // should this server act only as hub?
	StepLimit            int    // Boost limit
	ListenPort           int    // what port to listen on for http
	MinStoreTime         int    //minimum time in seconds for storage
	MaxStoreTime         int    // maximum time in seconds for storage
	// contains filtered or unexported fields
}

MessageServer provides handlers

func New

func New(path string, pubKey, privKey []byte) (*MessageServer, error)

New returns a MessageServer

func (MessageServer) AuthenticatePeer

func (ms MessageServer) AuthenticatePeer(authStr string) error

AuthenticatePeer verifies an existing authStr and matches it to the known peers

func (MessageServer) Delete

func (ms MessageServer) Delete(w http.ResponseWriter, r *http.Request)

Delete implements the delete call for messages

func (MessageServer) Fetch

func (ms MessageServer) Fetch(w http.ResponseWriter, r *http.Request)

Fetch returns a single message

func (MessageServer) FetchPeers

func (ms MessageServer) FetchPeers()

FetchPeers checks the peers for new messages, and downloads them

func (MessageServer) FetchPost

func (ms MessageServer) FetchPost(url, auth string, msgID [message.MessageIDSize]byte, expireRequest uint64) error

FetchPost fetches a post from a peer and adds it

func (MessageServer) FetchRun

func (ms MessageServer) FetchRun()

FetchRun is called when it is time to update peer information and load messages

func (MessageServer) GenPostHandler

func (ms MessageServer) GenPostHandler(oneTime bool) func(http.ResponseWriter, *http.Request)

GenPostHandler returns a handler for message posting

func (MessageServer) GetGlobalIndex

func (ms MessageServer) GetGlobalIndex(w http.ResponseWriter, r *http.Request)

GetGlobalIndex returns the global index

func (MessageServer) GetKeyIndex

func (ms MessageServer) GetKeyIndex(w http.ResponseWriter, r *http.Request)

GetKeyIndex returns the index for a key

func (MessageServer) GetNotify

func (ms MessageServer) GetNotify(w http.ResponseWriter, r *http.Request)

GetNotify receives notifications

func (MessageServer) LoadPeers

func (ms MessageServer) LoadPeers()

LoadPeers from file

func (MessageServer) NotifyPeers

func (ms MessageServer) NotifyPeers()

NotifyPeers runs notification for all peers

func (MessageServer) PeerKnown

func (ms MessageServer) PeerKnown(PubKey *[ed25519.PublicKeySize]byte) bool

PeerKnown tests if a peer is known

func (MessageServer) ProcessPost

func (ms MessageServer) ProcessPost(postdata io.ReadCloser, oneTime bool, expireRequest uint64) string

ProcessPost verifies and adds a post to the database

func (MessageServer) RandomSleep

func (ms MessageServer) RandomSleep()

RandomSleep makes the go routine sleep for a random time up to ms.MaxSleep

func (MessageServer) RunServer

func (ms MessageServer) RunServer()

RunServer starts the HTTP handlers

func (MessageServer) ServeID

func (ms MessageServer) ServeID(w http.ResponseWriter, r *http.Request)

ServeID returns server information

type Peer

type Peer struct {
	PubKey [ed25519.PublicKeySize]byte // Peer's public key for ping authentication
	URL    string                      // Peer's URL
	IsHub  bool                        // Is the peer a hub?
}

Peer is a single peer as loaded from file

type PeerEncoded

type PeerEncoded struct {
	PubKey string
	URL    string
	IsHub  bool
}

PeerEncoded is an encoded peer

type PeerList

type PeerList map[[ed25519.PublicKeySize]byte]Peer

PeerList contains all peers

type PeerListEncoded

type PeerListEncoded []PeerEncoded

PeerListEncoded .

type ServerInfo

type ServerInfo struct {
	Time            int64
	AuthPubKey      string
	AuthChallenge   string
	MaxPostSize     int64    // Maximum post size
	MinPostSize     int      //Minimum post size
	MinHashCashBits byte     // Minimum hashcash bits required
	Peers           []string // list of known peers
}

ServerInfo public server info

Jump to

Keyboard shortcuts

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