@@ -7,19 +7,12 @@ import (
7
7
"github.com/ethersphere/swarm/pss/message"
8
8
)
9
9
10
- type Outbox interface {
11
- Enqueue (outboxMsg * outboxMsg ) error
12
- Start ()
13
- Stop ()
14
- SetForwardFunction (forwardFunc forwardFunction ) // Needed right now to mock forwardFunc in one pss_tests.go test
15
- }
16
-
17
10
type Config struct {
18
11
NumberSlots int
19
12
Forward forwardFunction
20
13
}
21
14
22
- type outbox struct {
15
+ type Outbox struct {
23
16
forwardFunc forwardFunction
24
17
queue []* outboxMsg
25
18
slots chan int
@@ -30,12 +23,8 @@ type forwardFunction func(msg *message.Message) error
30
23
31
24
var ErrOutboxFull = errors .New ("outbox full" )
32
25
33
- func New (config * Config ) Outbox {
34
- return newOutbox (config )
35
- }
36
-
37
- func newOutbox (config * Config ) * outbox {
38
- outbox := outbox {
26
+ func NewOutbox (config * Config ) * Outbox {
27
+ outbox := & Outbox {
39
28
forwardFunc : config .Forward ,
40
29
queue : make ([]* outboxMsg , config .NumberSlots ),
41
30
slots : make (chan int , config .NumberSlots ),
@@ -45,22 +34,22 @@ func newOutbox(config *Config) *outbox {
45
34
for i := 0 ; i < cap (outbox .slots ); i ++ {
46
35
outbox .slots <- i
47
36
}
48
- return & outbox
37
+ return outbox
49
38
}
50
39
51
- func (o * outbox ) Start () {
40
+ func (o * Outbox ) Start () {
52
41
log .Info ("Starting outbox" )
53
42
go o .processOutbox ()
54
43
}
55
44
56
- func (o * outbox ) Stop () {
57
- log .Warn ("Stopping outbox" )
45
+ func (o * Outbox ) Stop () {
46
+ log .Info ("Stopping outbox" )
58
47
close (o .process )
59
48
}
60
49
61
50
// Enqueue a new element in the outbox if there is any slot available.
62
51
// Then send it to process. This method is blocking in the process channel!
63
- func (o * outbox ) Enqueue (outboxMsg * outboxMsg ) error {
52
+ func (o * Outbox ) Enqueue (outboxMsg * outboxMsg ) error {
64
53
// first we try to obtain a slot in the outbox
65
54
select {
66
55
case slot := <- o .slots :
@@ -76,7 +65,7 @@ func (o *outbox) Enqueue(outboxMsg *outboxMsg) error {
76
65
}
77
66
78
67
//ProcessOutbox starts a routine that tries to forward messages present in the outbox queue
79
- func (o * outbox ) processOutbox () {
68
+ func (o * Outbox ) processOutbox () {
80
69
for slot := range o .process {
81
70
go func (slot int ) {
82
71
msg := o .msg (slot )
@@ -96,22 +85,22 @@ func (o *outbox) processOutbox() {
96
85
}(slot )
97
86
}
98
87
}
99
- func (o * outbox ) SetForwardFunction (forwardFunc forwardFunction ) {
88
+ func (o * Outbox ) SetForwardFunction (forwardFunc forwardFunction ) {
100
89
o .forwardFunc = forwardFunc
101
90
}
102
91
103
- func (o * outbox ) msg (slot int ) * outboxMsg {
92
+ func (o * Outbox ) msg (slot int ) * outboxMsg {
104
93
return o .queue [slot ]
105
94
}
106
95
107
- func (o * outbox ) free (slot int ) {
96
+ func (o * Outbox ) free (slot int ) {
108
97
o .slots <- slot
109
98
}
110
99
111
- func (o * outbox ) requeue (slot int ) {
100
+ func (o * Outbox ) requeue (slot int ) {
112
101
o .process <- slot
113
102
}
114
103
115
- func (o * outbox ) len () int {
104
+ func (o * Outbox ) len () int {
116
105
return cap (o .slots ) - len (o .slots )
117
106
}
0 commit comments