| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- package modules
-
- import (
- "errors"
- "fmt"
- "log"
- "net"
- "net/rpc"
- )
-
- //temporary type for matching manager
- type match_manager struct{}
-
- func (match_mng *match_manager) matching(queue *MsgQueue) {
- //msg := queue.pop(true)
- //Implement here ~~
- }
-
- func (match_mng *match_manager) add_subscription(msg MsgUnit) {
-
- }
-
- //temporary type for secure(key) manager
- type secure_manager struct{}
-
- type Moscato struct {
- queue MsgQueue
- ms_mng MStable
- match_mng match_manager
- secure_mng secure_manager
- }
-
- // Send - rpc를 이용하여 msg전송
- func Send(ipaddr string, message MsgUnit) error {
- return nil
- }
-
- // Recieve - rpc를 이용하여 msg전달 받음(rpc call)
- func (moscato *Moscato) Recieve(msg MsgUnit) (MsgUnit, error) {
- msg_type := msg.CheckType()
-
- //메세지 타입에 따라 다르게 처리
- switch msg_type {
-
- case KSM: //Key share msg
-
- case PM: //Publish msg
- moscato.queue.push(msg.(*PublishMsg))
-
- case SM: //Subscription msg
- moscato.match_mng.add_subscription(msg.(*SubscriptionMsg))
-
- case RM: //Register msg
- //var newmsg RegisterMsg
- var newmsg = msg.(*RegisterMsg)
- newNode := MSnode{newmsg.from, newmsg.from}
- moscato.ms_mng.add_microservice(newNode)
-
- case WM: //Withdraw msg
- moscato.ms_mng.remove_microservice(msg.(*WithdrawMsg).from)
-
- default:
- return nil, errors.New("Message type Error: Not registered message type")
- }
-
- return msg, nil
- }
-
- func (moscato *Moscato) Run() {
- //모스카토 구조체 변수 초기화
- moscato.queue.queue_init()
-
- //go routine -> matching 동작
- go moscato.match_mng.matching(&moscato.queue)
-
- //rpc 등록 -> Receive함수
- rpc.Register(moscato)
- moscato.Listen()
- }
-
- func (moscato *Moscato) Listen() {
- l, err := net.Listen("tcp", fmt.Sprintf(":%v", 8160))
-
- if err != nil {
- log.Fatal(fmt.Sprintf("Unable to listen on given port: %s", err))
- }
- defer l.Close()
-
- for {
- conn, _ := l.Accept()
- go rpc.ServeConn(conn)
- }
- }
|