Commit e39a9483 authored by David Stainton's avatar David Stainton

Move constants into constants module

parent 3b307831
......@@ -28,4 +28,18 @@ const (
// round trip timeout threshold. Used for GC and for blocking
// on reply in Session's BlockingSendUnreliableMessage method.
RoundTripTimeSlop = 8 * time.Second
// TimeSkewWarnDelta is the client connection time skew threshold
// where clients print a warning log entry.
TimeSkewWarnDelta = 2 * time.Minute
// LoopService is the name of the Katzenpost loop service.
LoopService = "loop"
// GarbageCollectionInterval is the time interval between running our
// SURB ID Map garbage collection routine.
GarbageCollectionInterval = 10 * time.Minute
// MaxEgressQueueSize is the maximum size of the egress queue.
MaxEgressQueueSize = 40
)
......@@ -19,10 +19,9 @@ package client
import (
"errors"
"sync"
)
// MaxQueueSize is the maximum queue size.
const MaxQueueSize = 40
"github.com/katzenpost/client/constants"
)
// ErrQueueFull is the error issued when the queue is full.
var ErrQueueFull = errors.New("queue is full")
......@@ -47,7 +46,7 @@ type EgressQueue interface {
// for messages sent by the client.
type Queue struct {
sync.Mutex
content [MaxQueueSize]Item
content [constants.MaxEgressQueueSize]Item
readHead int
writeHead int
len int
......@@ -58,11 +57,11 @@ type Queue struct {
func (q *Queue) Push(e Item) error {
q.Lock()
defer q.Unlock()
if q.len >= MaxQueueSize {
if q.len >= constants.MaxEgressQueueSize {
return ErrQueueFull
}
q.content[q.writeHead] = e
q.writeHead = (q.writeHead + 1) % MaxQueueSize
q.writeHead = (q.writeHead + 1) % constants.MaxEgressQueueSize
q.len++
return nil
}
......@@ -77,7 +76,7 @@ func (q *Queue) Pop() (Item, error) {
}
result := q.content[q.readHead]
q.content[q.readHead] = &Message{}
q.readHead = (q.readHead + 1) % MaxQueueSize
q.readHead = (q.readHead + 1) % constants.MaxEgressQueueSize
q.len--
return result, nil
}
......
......@@ -103,8 +103,7 @@ func (s *Session) doSend(msg *Message) {
func (s *Session) sendLoopDecoy() {
s.log.Info("sending loop decoy")
const loopService = "loop"
serviceDesc, err := s.GetService(loopService)
serviceDesc, err := s.GetService(cConstants.LoopService)
if err != nil {
err := errors.New("failure to get loop service")
s.log.Error(err.Error())
......
......@@ -168,8 +168,7 @@ func (s *Session) eventSinkWorker() {
}
func (s *Session) garbageCollectionWorker() {
const garbageCollectionInterval = 10 * time.Minute
timer := time.NewTimer(garbageCollectionInterval)
timer := time.NewTimer(cConstants.GarbageCollectionInterval)
defer timer.Stop()
for {
select {
......@@ -178,7 +177,7 @@ func (s *Session) garbageCollectionWorker() {
return
case <-timer.C:
s.garbageCollect()
timer.Reset(garbageCollectionInterval)
timer.Reset(cConstants.GarbageCollectionInterval)
}
}
}
......
......@@ -21,6 +21,7 @@ import (
"fmt"
"time"
"github.com/katzenpost/client/constants"
"github.com/katzenpost/client/poisson"
"github.com/katzenpost/core/pki"
)
......@@ -71,7 +72,6 @@ func (s *Session) setTimers(doc *pki.Document) {
func (s *Session) connStatusChange(op opConnStatusChanged) bool {
isConnected := op.isConnected
if isConnected {
const skewWarnDelta = 2 * time.Minute
s.onlineAt = time.Now()
skew := s.minclient.ClockSkew()
......@@ -79,7 +79,7 @@ func (s *Session) connStatusChange(op opConnStatusChanged) bool {
if absSkew < 0 {
absSkew = -absSkew
}
if absSkew > skewWarnDelta {
if absSkew > constants.TimeSkewWarnDelta {
// Should this do more than just warn? Should this
// use skewed time? I don't know.
s.log.Warningf("The observed time difference between the host and provider clocks is '%v'. Correct your system time.", skew)
......@@ -183,9 +183,8 @@ func (s *Session) sendFromQueueOrDecoy() {
}
func (s *Session) isDocValid(doc *pki.Document) error {
const serviceLoop = "loop"
for _, provider := range doc.Providers {
_, ok := provider.Kaetzchen[serviceLoop]
_, ok := provider.Kaetzchen[constants.LoopService]
if !ok {
return errors.New("found a Provider which does not have the loop service")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment