~hockeypuck/hockeypuck/0.8

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
   Hockeypuck - OpenPGP key server
   Copyright (C) 2012  Casey Marshall

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as published by
   the Free Software Foundation, version 3.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package hockeypuck

import (
	"net/http"
)

// Size of the worker channels. May want to make this configurable.
const HKP_CHAN_SIZE = 20

// Operation type in request.
type Operation int

// Hockeypuck supported Operations.
const (
	UnknownOperation           = iota
	Get              Operation = iota
	Index            Operation = iota
	Vindex           Operation = iota
	Status           Operation = iota
)

// Option bit mask in request.
type Option int

// Hockeypuck supported HKP options.
const (
	MachineReadable Option = 1 << iota
	NotModifiable   Option = 1 << iota
	NoOption               = Option(0)
)

// An HKP "lookup" request.
type Lookup struct {
	Op          Operation
	Search      string
	Option      Option
	Fingerprint bool
	Exact       bool
	// Hostname and port are used with op=status
	Hostname     string
	Port         int
	responseChan ResponseChan
}

// Get the response channel that a worker processing
// a lookup request will use to send the response back to the
// web server.
func (l *Lookup) Response() ResponseChan {
	return l.responseChan
}

// An HKP "add" request.
type Add struct {
	Keytext      string
	Option       Option
	responseChan ResponseChan
}

// Get the response channel for sending a response to an add request.
func (a *Add) Response() ResponseChan {
	return a.responseChan
}

// Interface for requests that have a response channel.
type HasResponse interface {
	Response() ResponseChan
}

// Worker responses.
type Response interface {
	Error() error
	WriteTo(http.ResponseWriter) error
}

// Channel of Lookup requests, to be read by a 'lookup' worker.
type LookupChan chan *Lookup

// Channel of Add requests, to be read by an 'add' worker.
type AddChan chan *Add

// Response channel to which the workers send their results.
type ResponseChan chan Response

// The HKP server.
type HkpServer struct {
	LookupRequests LookupChan
	AddRequests    AddChan
}