-
Notifications
You must be signed in to change notification settings - Fork 13
/
server.go
73 lines (57 loc) · 1.33 KB
/
server.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
// Copyright (c) 2014-2016 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpc
import (
"github.com/bitmark-inc/bitmarkd/counter"
"github.com/bitmark-inc/logger"
"io"
"net/rpc"
"net/rpc/jsonrpc"
"time"
)
// limit the number of gets
const MaximumGetSize = 100
// the argument passed to the callback
type ServerArgument struct {
Log *logger.L
StartTime time.Time
}
var connectionCount counter.Counter
// listener callback
func Callback(conn io.ReadWriteCloser, argument interface{}) {
serverArgument := argument.(*ServerArgument)
if nil == serverArgument {
panic("rpc: nil serverArgument")
}
if nil == serverArgument.Log {
panic("rpc: nil serverArgument.Log")
}
assets := &Assets{
log: serverArgument.Log,
}
bitmark := &Bitmark{
log: serverArgument.Log,
}
bitmarks := &Bitmarks{
log: serverArgument.Log,
}
owner := &Owner{
log: serverArgument.Log,
}
node := &Node{
log: serverArgument.Log,
start: serverArgument.StartTime,
}
server := rpc.NewServer()
server.Register(assets)
server.Register(bitmark)
server.Register(bitmarks)
server.Register(owner)
server.Register(node)
connectionCount.Increment()
defer connectionCount.Decrement()
codec := jsonrpc.NewServerCodec(conn)
defer codec.Close()
server.ServeCodec(codec)
}