forked from FactomProject/factomd
/
NetworkProcessor.go
82 lines (69 loc) · 1.77 KB
/
NetworkProcessor.go
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
// Copyright 2015 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package main
import (
"fmt"
"github.com/FactomProject/factomd/btcd"
"github.com/FactomProject/factomd/common/interfaces"
"github.com/FactomProject/factomd/common/messages"
"github.com/FactomProject/factomd/log"
"github.com/davecgh/go-spew/spew"
//"reflect"
"time"
)
var _ = spew.Sdump
var _ = log.Printf
var _ = fmt.Print
func NetworkProcessor(state interfaces.IState) {
netloop:
for {
// This loop looks at the input queues and the invalid queues and
// Handles messages as they come in. If nothing is read, it sleeps
// for 500 milliseconds. Note you only sleep if both queues test
// to be empty.
select {
case msg, ok := <-state.NetworkInMsgQueue():
if ok {
//log.Printf("NetworkIn: %s\n", spew.Sdump(msg))
if state.PrintType(msg.Type()) {
log.Printf("Ignored: NetworkIn: %s\n", msg.String())
}
state.InMsgQueue() <- msg
continue netloop
}
default:
}
select {
case msg, ok := <-state.NetworkOutMsgQueue():
if ok {
var _ = msg
//log.Printf("NetworkOut: %s\n", msg.String())
if state.PrintType(msg.Type()) {
log.Printf("Ignored: NetworkOut: %s\n", msg.String())
}
switch msg.(type) {
case *messages.EOM:
msgeom := msg.(*messages.EOM)
server := state.GetServer().(*btcd.Server)
server.BroadcastMessage(msgeom)
default:
}
continue netloop
}
default:
}
select {
case msg, ok := <-state.NetworkInvalidMsgQueue():
if ok {
var _ = msg
if state.PrintType(msg.Type()) {
log.Printf("%20s %s\n", "Invalid:", msg.String())
}
continue netloop
}
default:
}
time.Sleep(time.Duration(500) * time.Millisecond)
}
}