|
|
@@ -1 +1,93 @@
|
|
1
|
1
|
package modules
|
|
|
2
|
+
|
|
|
3
|
+import (
|
|
|
4
|
+ "errors"
|
|
|
5
|
+ "fmt"
|
|
|
6
|
+ "log"
|
|
|
7
|
+ "net"
|
|
|
8
|
+ "net/rpc"
|
|
|
9
|
+)
|
|
|
10
|
+
|
|
|
11
|
+//temporary type for matching manager
|
|
|
12
|
+type match_manager struct{}
|
|
|
13
|
+
|
|
|
14
|
+func (match_mng *match_manager) matching(queue *MsgQueue) {
|
|
|
15
|
+ //msg := queue.pop(true)
|
|
|
16
|
+ //Implement here ~~
|
|
|
17
|
+}
|
|
|
18
|
+
|
|
|
19
|
+func (match_mng *match_manager) add_subscription(msg MsgUnit) {
|
|
|
20
|
+
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+//temporary type for secure(key) manager
|
|
|
24
|
+type secure_manager struct{}
|
|
|
25
|
+
|
|
|
26
|
+type Moscato struct {
|
|
|
27
|
+ queue MsgQueue
|
|
|
28
|
+ ms_mng MStable
|
|
|
29
|
+ match_mng match_manager
|
|
|
30
|
+ secure_mng secure_manager
|
|
|
31
|
+}
|
|
|
32
|
+
|
|
|
33
|
+// Send - rpc를 이용하여 msg전송
|
|
|
34
|
+func Send(ipaddr string, message MsgUnit) error {
|
|
|
35
|
+ return nil
|
|
|
36
|
+}
|
|
|
37
|
+
|
|
|
38
|
+// Recieve - rpc를 이용하여 msg전달 받음(rpc call)
|
|
|
39
|
+func (moscato *Moscato) Recieve(msg MsgUnit) (MsgUnit, error) {
|
|
|
40
|
+ msg_type := msg.CheckType()
|
|
|
41
|
+
|
|
|
42
|
+ //메세지 타입에 따라 다르게 처리
|
|
|
43
|
+ switch msg_type {
|
|
|
44
|
+
|
|
|
45
|
+ case KSM: //Key share msg
|
|
|
46
|
+
|
|
|
47
|
+ case PM: //Publish msg
|
|
|
48
|
+ moscato.queue.push(msg.(*PublishMsg))
|
|
|
49
|
+
|
|
|
50
|
+ case SM: //Subscription msg
|
|
|
51
|
+ moscato.match_mng.add_subscription(msg.(*SubscriptionMsg))
|
|
|
52
|
+
|
|
|
53
|
+ case RM: //Register msg
|
|
|
54
|
+ //var newmsg RegisterMsg
|
|
|
55
|
+ var newmsg = msg.(*RegisterMsg)
|
|
|
56
|
+ newNode := MSnode{newmsg.from, newmsg.from}
|
|
|
57
|
+ moscato.ms_mng.add_microservice(newNode)
|
|
|
58
|
+
|
|
|
59
|
+ case WM: //Withdraw msg
|
|
|
60
|
+ moscato.ms_mng.remove_microservice(msg.(*WithdrawMsg).from)
|
|
|
61
|
+
|
|
|
62
|
+ default:
|
|
|
63
|
+ return nil, errors.New("Message type Error: Not registered message type")
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ return msg, nil
|
|
|
67
|
+}
|
|
|
68
|
+
|
|
|
69
|
+func (moscato *Moscato) Run() {
|
|
|
70
|
+ //모스카토 구조체 변수 초기화
|
|
|
71
|
+ moscato.queue.queue_init()
|
|
|
72
|
+
|
|
|
73
|
+ //go routine -> matching 동작
|
|
|
74
|
+ go moscato.match_mng.matching(&moscato.queue)
|
|
|
75
|
+
|
|
|
76
|
+ //rpc 등록 -> Receive함수
|
|
|
77
|
+ rpc.Register(moscato)
|
|
|
78
|
+ moscato.Listen()
|
|
|
79
|
+}
|
|
|
80
|
+
|
|
|
81
|
+func (moscato *Moscato) Listen() {
|
|
|
82
|
+ l, err := net.Listen("tcp", fmt.Sprintf(":%v", 8160))
|
|
|
83
|
+
|
|
|
84
|
+ if err != nil {
|
|
|
85
|
+ log.Fatal(fmt.Sprintf("Unable to listen on given port: %s", err))
|
|
|
86
|
+ }
|
|
|
87
|
+ defer l.Close()
|
|
|
88
|
+
|
|
|
89
|
+ for {
|
|
|
90
|
+ conn, _ := l.Accept()
|
|
|
91
|
+ go rpc.ServeConn(conn)
|
|
|
92
|
+ }
|
|
|
93
|
+}
|