forked from smallnest/rpcx
/
server.go
54 lines (41 loc) · 979 Bytes
/
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
package main
import (
"crypto/sha1"
"fmt"
"golang.org/x/crypto/pbkdf2"
"github.com/smallnest/rpcx"
kcp "github.com/xtaci/kcp-go"
)
type Args struct {
A int `msg:"a"`
B int `msg:"b"`
}
type Reply struct {
C int `msg:"c"`
}
type Arith int
func (t *Arith) Mul(args *Args, reply *Reply) error {
reply.C = args.A * args.B
return nil
}
func (t *Arith) Error(args *Args, reply *Reply) error {
panic("ERROR")
}
const cryptKey = "rpcx-key"
const cryptSalt = "rpcx-salt"
func main() {
server := rpcx.NewServer()
server.RegisterName("Arith", new(Arith))
pass := pbkdf2.Key([]byte(cryptKey), []byte(cryptSalt), 4096, 32, sha1.New)
bc, err := kcp.NewAESBlockCrypt(pass)
ln, err := kcp.ListenWithOptions("127.0.0.1:8972", bc, 10, 3)
// kcplistener := ln
// kcplistener.SetReadBuffer(16 * 1024 * 1024)
// kcplistener.SetWriteBuffer(16 * 1024 * 1024)
// kcplistener.SetDSCP(46)
if err != nil {
fmt.Println(err.Error())
return
}
server.ServeListener(ln)
}