github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/core/discovery/brokerdiscovery/messaging_register.go (about) 1 /* 2 * Copyright (C) 2019 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package brokerdiscovery 19 20 import ( 21 "github.com/mysteriumnetwork/node/communication" 22 "github.com/mysteriumnetwork/node/communication/nats" 23 "github.com/mysteriumnetwork/node/identity" 24 "github.com/mysteriumnetwork/node/market" 25 ) 26 27 // registerMessage structure represents message that the Provider sends about newly announced Proposal 28 type registerMessage struct { 29 Proposal market.ServiceProposal `json:"proposal"` 30 } 31 32 const registerEndpoint = communication.MessageEndpoint("*.proposal-register.v3") 33 34 // registerProducer 35 type registerProducer struct { 36 message *registerMessage 37 signer identity.Signer 38 } 39 40 // GetMessageEndpoint returns endpoint where to send messages 41 func (p *registerProducer) GetMessageEndpoint() (communication.MessageEndpoint, error) { 42 subj, err := nats.SignedSubject(p.signer, string(registerEndpoint)) 43 return communication.MessageEndpoint(subj), err 44 } 45 46 // Produce creates message which will be serialized to endpoint 47 func (p *registerProducer) Produce() (requestPtr interface{}) { 48 return p.message 49 } 50 51 // registerConsumer 52 type registerConsumer struct { 53 Callback func(registerMessage) error 54 } 55 56 // GetMessageEndpoint returns endpoint where to receive messages 57 func (c *registerConsumer) GetMessageEndpoint() (communication.MessageEndpoint, error) { 58 return registerEndpoint, nil 59 } 60 61 // NewMessage creates struct where message from endpoint will be serialized 62 func (c *registerConsumer) NewMessage() (messagePtr interface{}) { 63 return ®isterMessage{} 64 } 65 66 // Consume handles messages from endpoint 67 func (c *registerConsumer) Consume(messagePtr interface{}) error { 68 return c.Callback(*messagePtr.(*registerMessage)) 69 }