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 (moscato *Moscato)Send(ipaddr string, message MsgUnit, reply []byte)([]byte, error) { reply,err:=message.ConvertToJson() return reply,err } // 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) } }