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 //종류 } func (msg Message) From() string { return msg.from } func (msg Message) Version() string { return msg.version } func (msg Message) Time() string { return msg.time } func (msg Message) Kind() int { return msg.kind } 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 topic []int64 //대주제 value []int64 //topic의 세부적인 내용 content []int64 // 내용 } //구독 정보를 담은 메세지 type SubscriptionMsg struct { Message topic []int64 //대주제 value []int64 //피연산자 operator []string //연산자 isAlpha bool // 범위연산인지 단순비교연산인지 구분 가능하게 함 } //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 }