|
|
@@ -10,12 +10,40 @@ import (
|
|
10
|
10
|
type Microservice struct {
|
|
11
|
11
|
}
|
|
12
|
12
|
|
|
13
|
|
-func (microservice *Microservice) Send2MM() {
|
|
|
13
|
+type Moscato struct {
|
|
|
14
|
+}
|
|
|
15
|
+
|
|
|
16
|
+type Reply struct {
|
|
|
17
|
+ receivemsg MsgUnit
|
|
|
18
|
+}
|
|
14
|
19
|
|
|
|
20
|
+func (microservice *Microservice)MS_Receive(msg MsgUnit, reply *Reply)error{
|
|
|
21
|
+ go microservice.Receive(msg)
|
|
|
22
|
+ return nil
|
|
15
|
23
|
}
|
|
16
|
24
|
|
|
17
|
|
-func (microservice *Microservice) Send2client() {
|
|
|
25
|
+//Receive - MicroService가 msg 받음// MS.go들어가야할 함수
|
|
|
26
|
+func (microservice *Microservice)Receive(msg MsgUnit)error{
|
|
|
27
|
+ msg_type:=msg.CheckType()
|
|
|
28
|
+
|
|
|
29
|
+ switch msg_type{
|
|
|
30
|
+ case KGM://Key Gen Msg
|
|
|
31
|
+
|
|
|
32
|
+ case KSM://Key Share Msg
|
|
|
33
|
+
|
|
|
34
|
+ case SM://Subscription Msg
|
|
|
35
|
+
|
|
|
36
|
+ }
|
|
|
37
|
+ return nil
|
|
|
38
|
+}
|
|
18
|
39
|
|
|
|
40
|
+func (microservice *Microservice) Send2MM(client *rpc.Client,msg MsgUnit) {
|
|
|
41
|
+ reply:=new(Reply)
|
|
|
42
|
+ err:=client.Call("Moscato.MM_Receive", msg,reply)
|
|
|
43
|
+ if err !=nil{
|
|
|
44
|
+ fmt.Println(err)
|
|
|
45
|
+ return
|
|
|
46
|
+ }
|
|
19
|
47
|
}
|
|
20
|
48
|
|
|
21
|
49
|
func (microservice *Microservice) Listen() {
|
|
|
@@ -32,6 +60,70 @@ func (microservice *Microservice) Listen() {
|
|
32
|
60
|
}
|
|
33
|
61
|
}
|
|
34
|
62
|
|
|
|
63
|
+
|
|
|
64
|
+func handleSum(ln net.Listener){
|
|
|
65
|
+ for {
|
|
|
66
|
+ conn, err := ln.Accept() // 클라이언트가 연결되면 TCP 연결을 리턴
|
|
|
67
|
+ if err != nil {
|
|
|
68
|
+ continue
|
|
|
69
|
+ }
|
|
|
70
|
+
|
|
|
71
|
+ defer func(conn net.Conn) {
|
|
|
72
|
+ err := conn.Close()
|
|
|
73
|
+ if err != nil {
|
|
|
74
|
+
|
|
|
75
|
+ }
|
|
|
76
|
+ }(conn) // main 함수가 끝나기 직전에 TCP 연결을 닫음
|
|
|
77
|
+
|
|
|
78
|
+ go rpc.ServeConn(conn) // RPC를 처리하는 함수를 고루틴으로 실행
|
|
|
79
|
+ }
|
|
|
80
|
+}
|
|
|
81
|
+
|
|
|
82
|
+func callRPC(client *rpc.Client, msg MsgUnit, err error){
|
|
|
83
|
+ reply := new(MsgUnit)
|
|
|
84
|
+ err = client.Call("Moscato.MM_Receive", msg, reply) // Calc.Sum 함수 호출
|
|
|
85
|
+ if err != nil {
|
|
|
86
|
+ fmt.Println(err)
|
|
|
87
|
+ return
|
|
|
88
|
+ }
|
|
|
89
|
+}
|
|
|
90
|
+
|
|
35
|
91
|
func (microservice *Microservice) Run() {
|
|
|
92
|
+ err := rpc.Register(new(Microservice))
|
|
|
93
|
+ if err != nil {
|
|
|
94
|
+ return
|
|
|
95
|
+ } // Calc 타입의 인스턴스를 생성하여 RPC 서버에 등록
|
|
|
96
|
+ ln, err := net.Listen("tcp", ":6000") // TCP 프로토콜에 6000번 포트로 연결을 받음 local 나중에 8150
|
|
|
97
|
+ ln1, err1 := net.Listen("tcp", ":6001") // TCP 프로토콜에 6000번 포트로 연결을 받음 나중에 8160
|
|
|
98
|
+
|
|
|
99
|
+ if err != nil {
|
|
|
100
|
+ fmt.Println(err)
|
|
|
101
|
+ return
|
|
|
102
|
+ }
|
|
|
103
|
+ if err1 != nil {
|
|
|
104
|
+ fmt.Println(err)
|
|
|
105
|
+ return
|
|
|
106
|
+ }
|
|
|
107
|
+ defer func(ln net.Listener) {
|
|
|
108
|
+ err := ln.Close()
|
|
|
109
|
+ if err != nil {
|
|
|
110
|
+
|
|
|
111
|
+ }
|
|
|
112
|
+ }(ln) // main 함수가 종료되기 직전에 연결 대기를 닫음
|
|
|
113
|
+ defer func(ln1 net.Listener) {
|
|
|
114
|
+ err := ln1.Close()
|
|
|
115
|
+ if err != nil {
|
|
|
116
|
+
|
|
|
117
|
+ }
|
|
|
118
|
+ }(ln1) // main 함수가 종료되기 직전에 연결 대기를 닫음
|
|
|
119
|
+
|
|
|
120
|
+ /*client1, err := rpc.Dial("tcp", "127.0.0.1:6000") // RPC 서버에 연결
|
|
|
121
|
+ if err != nil {
|
|
|
122
|
+ fmt.Println(err)
|
|
|
123
|
+ return
|
|
|
124
|
+ }*/
|
|
36
|
125
|
|
|
|
126
|
+ go handleSum(ln)
|
|
|
127
|
+ go handleSum(ln1)
|
|
|
128
|
+ fmt.Scanln() // main 함수가 종료되지 않도록 대기=
|
|
37
|
129
|
}
|