package modules import "encoding/json" //import "strconv" //*****메세지 타입 상수화 const ( KGM = 1 + iota KSM PM SM RM WM ) //*****메세지 틀***** type Message struct { from string //ip주소 version string time string kind int //종류 } type MsgUnit interface { // ConvertToJson - send 전 json형식으로 바꾸는 함수 ConvertToJson() ([]byte, error) // CheckType - Message의 타입을 알려줌 CheckType() int } //*****각 메세지 형식 및 정의********** //KeyGen 명령 메세지 type KeyGenMsg struct { Message iptable []string } //Key공유 메세지 type KeyShareMsg struct { Message key string } //전달할 내용을 담은 메세지 type PublishMsg struct { Message subscription []int64 //대주제 content []int64 // 내용 } //구독 정보를 담은 메세지 type SubscriptionMsg struct { Message subscription []int64 //대주제 content []int64 //내용 value string //범위 } //Microservice 등록 메세지 type RegisterMsg struct { Message } //Microservice 탈퇴 메세지 type WithdrawMsg struct { Message } //************************** func (msg *KeyGenMsg) ConvertToJson() ([]byte, error) { js := msg jsonBytes, err := json.Marshal(js) return jsonBytes, err } func (msg *KeyShareMsg) ConvertToJson() ([]byte, error) { js := msg jsonBytes, err := json.Marshal(js) return jsonBytes, err } func (msg *PublishMsg) ConvertToJson() ([]byte, error) { js := msg jsonBytes, err := json.Marshal(js) return jsonBytes, err } func (msg *SubscriptionMsg) ConvertToJson() ([]byte, error) { js := msg jsonBytes, err := json.Marshal(js) return jsonBytes, err } func (msg *RegisterMsg) ConvertToJson() ([]byte, error) { js := msg jsonBytes, err := json.Marshal(js) return jsonBytes, err } func (msg *WithdrawMsg) ConvertToJson() ([]byte, error) { js := msg jsonBytes, err := json.Marshal(js) return jsonBytes, err } func (msg Message) CheckType() int { return msg.kind } //KeyGenMsg 생성자 func NewKeyGenMsg(table *MStable) *KeyGenMsg{ m:= &KeyGenMsg{} for _,value:= range table.NodeTable{ m.iptable=append(m.iptable,value.Getipaddr()) } return m }