diff --git a/broadcast/client.go b/broadcast/client.go index 63d2c03ce4e5354fdca08b60b0c539849573e156..1b4891a00bdf4d8ae9ce6bf31c2b020b356fa114 100644 --- a/broadcast/client.go +++ b/broadcast/client.go @@ -16,17 +16,21 @@ import ( "gitlab.com/elixxir/crypto/fastRNG" ) -// broadcastClient implements the Channel interface for sending/receiving asymmetric or symmetric broadcast messages +// broadcastClient implements the [broadcast.Channel] interface for sending/ +// receiving asymmetric or symmetric broadcast messages. type broadcastClient struct { channel *crypto.Channel net Client rng *fastRNG.StreamGenerator } -type NewBroadcastChannelFunc func(channel *crypto.Channel, net Client, rng *fastRNG.StreamGenerator) (Channel, error) +type NewBroadcastChannelFunc func(channel *crypto.Channel, net Client, + rng *fastRNG.StreamGenerator) (Channel, error) -// NewBroadcastChannel creates a channel interface based on crypto.Channel, accepts net client connection & callback for received messages -func NewBroadcastChannel(channel *crypto.Channel, net Client, rng *fastRNG.StreamGenerator) (Channel, error) { +// NewBroadcastChannel creates a channel interface based on [broadcast.Channel]. +// It accepts a Cmix client connection. +func NewBroadcastChannel(channel *crypto.Channel, net Client, + rng *fastRNG.StreamGenerator) (Channel, error) { bc := &broadcastClient{ channel: channel, net: net, @@ -46,7 +50,7 @@ func NewBroadcastChannel(channel *crypto.Channel, net Client, rng *fastRNG.Strea return bc, nil } -// RegisterListener adds a service to hear broadcast messages of a given type via the passed in callback +// RegisterListener registers a listener for broadcast messages. func (bc *broadcastClient) RegisterListener(listenerCb ListenerFunc, method Method) error { var tag string switch method { @@ -55,7 +59,8 @@ func (bc *broadcastClient) RegisterListener(listenerCb ListenerFunc, method Meth case RSAToPublic: tag = asymmetricRSAToPublicBroadcastServiceTag default: - return errors.Errorf("Cannot register listener for broadcast method %s", method) + return errors.Errorf( + "Cannot register listener for broadcast method %s", method) } p := &processor{ @@ -73,8 +78,8 @@ func (bc *broadcastClient) RegisterListener(listenerCb ListenerFunc, method Meth return nil } -// Stop unregisters the listener callback and stops the channel's identity -// from being tracked. +// Stop unregisters the listener callback and stops the channel's identity from +// being tracked. func (bc *broadcastClient) Stop() { // Removes currently tracked identity bc.net.RemoveIdentity(bc.channel.ReceptionID) @@ -83,12 +88,12 @@ func (bc *broadcastClient) Stop() { bc.net.DeleteClientService(bc.channel.ReceptionID) } -// Get returns the underlying crypto.Channel object. +// Get returns the underlying [broadcast.Channel] object. func (bc *broadcastClient) Get() *crypto.Channel { return bc.channel } -// MaxPayloadSize returns the maximum payload size for a symmetric broadcast +// MaxPayloadSize returns the maximum size for a symmetric broadcast payload. func (bc *broadcastClient) MaxPayloadSize() int { return bc.maxSymmetricPayload() } @@ -97,8 +102,8 @@ func (bc *broadcastClient) maxSymmetricPayload() int { return bc.channel.GetMaxSymmetricPayloadSize(bc.net.GetMaxMessageLength()) } -// MaxRSAToPublicPayloadSize return the maximum payload size for an RSAToPublic -// Asymmetric payload +// MaxRSAToPublicPayloadSize return the maximum payload size for a +// [broadcast.RSAToPublic] asymmetric payload. func (bc *broadcastClient) MaxRSAToPublicPayloadSize() int { return bc.maxRSAToPublicPayloadSizeRaw() - internalPayloadSizeLength } diff --git a/broadcast/interface.go b/broadcast/interface.go index 034550f0ba8def0de3639c13f9060a18baed17da..3c674c0db3438862296e8980afcb8177eb3d2a9a 100644 --- a/broadcast/interface.go +++ b/broadcast/interface.go @@ -24,46 +24,58 @@ import ( type ListenerFunc func(payload []byte, receptionID receptionID.EphemeralIdentity, round rounds.Round) -// Channel is the public-facing interface to interact with broadcast channels +// Channel is the public-facing interface to interact with broadcast channels. type Channel interface { - // MaxPayloadSize returns the maximum size for a symmetric broadcast payload + // MaxPayloadSize returns the maximum size for a symmetric broadcast + // payload. MaxPayloadSize() int // MaxRSAToPublicPayloadSize returns the maximum size for an asymmetric - // broadcast payload + // broadcast payload. MaxRSAToPublicPayloadSize() int - // Get returns the underlying crypto.Channel + // Get returns the underlying [broadcast.Channel] object. Get() *crypto.Channel - // Broadcast broadcasts the payload to the channel. The payload size must be - // equal to MaxPayloadSize or smaller. + // Broadcast broadcasts a payload to the channel. The payload must be of the + // size [Channel.MaxPayloadSize] or smaller. + // + // The network must be healthy to send. Broadcast(payload []byte, cMixParams cmix.CMIXParams) ( rounds.Round, ephemeral.Id, error) - // BroadcastWithAssembler broadcasts a payload over a symmetric channel. - // With a payload assembled after the round is selected, allowing the round - // info to be included in the payload. Network must be healthy to send. - // Requires a payload of size bc.MaxSymmetricPayloadSize() or smaller + // BroadcastWithAssembler broadcasts a payload over a channel with a payload + // assembled after the round is selected, allowing the round info to be + // included in the payload. + // + // The payload must be of the size [Channel.MaxPayloadSize] or smaller. + // + // The network must be healthy to send. BroadcastWithAssembler(assembler Assembler, cMixParams cmix.CMIXParams) ( rounds.Round, ephemeral.Id, error) - // BroadcastRSAtoPublic broadcasts the payload to the channel. Requires a - // healthy network state to send Payload length less than or equal to - // bc.MaxRSAToPublicPayloadSize, and the channel PrivateKey must be passed in + // BroadcastRSAtoPublic broadcasts the payload to the channel. + // + // The payload must be of the size [Channel.MaxRSAToPublicPayloadSize] or + // smaller and the channel [rsa.PrivateKey] must be passed in. + // + // The network must be healthy to send. BroadcastRSAtoPublic(pk rsa.PrivateKey, payload []byte, cMixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error) - // BroadcastRSAToPublicWithAssembler broadcasts the payload to the channel with - // a function which builds the payload based upon the ID of the selected round. - // Requires a healthy network state to send Payload must be shorter or equal in - // length to bc.MaxRSAToPublicPayloadSize when returned, and the channel - // PrivateKey must be passed in + // BroadcastRSAToPublicWithAssembler broadcasts the payload to the channel + // with a function that builds the payload based upon the ID of the selected + // round. + // + // The payload must be of the size [Channel.MaxRSAToPublicPayloadSize] or + // smaller and the channel [rsa.PrivateKey] must be passed in. + // + // The network must be healthy to send. BroadcastRSAToPublicWithAssembler( pk rsa.PrivateKey, assembler Assembler, cMixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error) - // RegisterListener registers a listener for broadcast messages + // RegisterListener registers a listener for broadcast messages. RegisterListener(listenerCb ListenerFunc, method Method) error // Stop unregisters the listener callback and stops the channel's identity @@ -74,8 +86,8 @@ type Channel interface { // Assembler is a function which allows a bre type Assembler func(rid id.Round) (payload []byte, err error) -// Client contains the methods from cmix.Client that are required by -// symmetricClient. +// Client contains the methods from [cmix.Client] that are required by +// broadcastClient. type Client interface { SendWithAssembler(recipient *id.ID, assembler cmix.MessageAssembler, cmixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error) diff --git a/broadcast/rsaToPublic.go b/broadcast/rsaToPublic.go index 0d1483b16437854f99fa4a31e5cd7c5050705f8e..26c4d0924af04c6464610f20fe8040ac1aa7b082 100644 --- a/broadcast/rsaToPublic.go +++ b/broadcast/rsaToPublic.go @@ -28,6 +28,13 @@ const ( // BroadcastRSAtoPublic broadcasts the payload to the channel. Requires a // healthy network state to send Payload length less than or equal to // bc.MaxRSAToPublicPayloadSize, and the channel PrivateKey must be passed in +// +// BroadcastRSAtoPublic broadcasts the payload to the channel. +// +// The payload must be of the size [broadcastClient.MaxRSAToPublicPayloadSize] +// or smaller and the channel [rsa.PrivateKey] must be passed in. +// +// The network must be healthy to send. func (bc *broadcastClient) BroadcastRSAtoPublic(pk rsa.PrivateKey, payload []byte, cMixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error) { // Confirm network health @@ -38,11 +45,14 @@ func (bc *broadcastClient) BroadcastRSAtoPublic(pk rsa.PrivateKey, return bc.BroadcastRSAToPublicWithAssembler(pk, assemble, cMixParams) } -// BroadcastRSAToPublicWithAssembler broadcasts the payload to the channel with -// a function which builds the payload based upon the ID of the selected round. -// Requires a healthy network state to send Payload must be shorter or equal in -// length to bc.MaxRSAToPublicPayloadSize when returned, and the channel -// PrivateKey must be passed in +// BroadcastRSAToPublicWithAssembler broadcasts the payload to the channel +// with a function that builds the payload based upon the ID of the selected +// round. +// +// The payload must be of the size [broadcastClient.MaxRSAToPublicPayloadSize] +// or smaller and the channel [rsa.PrivateKey] must be passed in. +// +// The network must be healthy to send. func (bc *broadcastClient) BroadcastRSAToPublicWithAssembler( pk rsa.PrivateKey, assembler Assembler, cMixParams cmix.CMIXParams) (rounds.Round, ephemeral.Id, error) { diff --git a/broadcast/symmetric.go b/broadcast/symmetric.go index 53c2d1e606e1f5e0b4a6d34235fab295514939ff..432c53c8cab2ae80ea16f915d0142136a0d1532d 100644 --- a/broadcast/symmetric.go +++ b/broadcast/symmetric.go @@ -19,7 +19,7 @@ import ( // Error messages. const ( - // symmetricClient.Broadcast + // broadcastClient.Broadcast errNetworkHealth = "cannot send broadcast when the network is not healthy" errPayloadSize = "size of payload %d must be less than %d" errBroadcastMethodType = "cannot call %s broadcast using %s channel" @@ -31,9 +31,10 @@ const ( symmetricBroadcastServiceTag = "SymmetricBroadcast" ) -// Broadcast broadcasts a payload over a symmetric channel. -// Network must be healthy to send -// Requires a payload of size bc.MaxSymmetricPayloadSize() or smaller +// Broadcast broadcasts a payload to a symmetric channel. The payload must be of +// size [broadcastClient.MaxPayloadSize] or smaller. +// +// The network must be healthy to send. func (bc *broadcastClient) Broadcast(payload []byte, cMixParams cmix.CMIXParams) ( rounds.Round, ephemeral.Id, error) { assemble := func(rid id.Round) ([]byte, error) { @@ -42,11 +43,13 @@ func (bc *broadcastClient) Broadcast(payload []byte, cMixParams cmix.CMIXParams) return bc.BroadcastWithAssembler(assemble, cMixParams) } -// BroadcastWithAssembler broadcasts a payload over a symmetric channel. With -// a payload assembled after the round is selected, allowing the round -// info to be included in the payload. -// Network must be healthy to send -// Requires a payload of size bc.MaxSymmetricPayloadSize() or smaller +// BroadcastWithAssembler broadcasts a payload over a symmetric channel with a +// payload assembled after the round is selected, allowing the round info to be +// included in the payload. +// +// The payload must be of the size [Channel.MaxPayloadSize] or smaller. +// +// The network must be healthy to send. func (bc *broadcastClient) BroadcastWithAssembler(assembler Assembler, cMixParams cmix.CMIXParams) ( rounds.Round, ephemeral.Id, error) { if !bc.net.IsHealthy() { diff --git a/channels/eventModel.go b/channels/eventModel.go index d5cd20b7d007b4f71f93bf3867690533fe5944cf..9ebb58f480efa9808fac10e48732cbca1a3f495d 100644 --- a/channels/eventModel.go +++ b/channels/eventModel.go @@ -8,7 +8,6 @@ package channels import ( - "fmt" "github.com/golang/protobuf/proto" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/client/cmix/identity/receptionID" @@ -253,8 +252,6 @@ func (e *events) receiveTextMessage(channelID *id.ID, } } - fmt.Println(channelID) - e.model.ReceiveMessage(channelID, messageID, senderUsername, txt.Text, timestamp, lease, round, status) } diff --git a/channels/manager.go b/channels/manager.go index 2c63aed82c7000b446b0617785775a1b1f8e3ad0..4547cf57f05acb849c5c67e4ad687a8a0a4ad5c5 100644 --- a/channels/manager.go +++ b/channels/manager.go @@ -46,8 +46,8 @@ type manager struct { broadcastMaker broadcast.NewBroadcastChannelFunc } -// Client contains the methods from cmix.Client that are required by -// symmetricClient. +// Client contains the methods from cmix.Client that are required by the +// [Manager]. type Client interface { GetMaxMessageLength() int SendWithAssembler(recipient *id.ID, assembler cmix.MessageAssembler, diff --git a/go.mod b/go.mod index e124f80f7e27b09cb5dd56de364a5ed397397edb..227ba6e5c700edca43d506df94fe23eb068a5a0d 100644 --- a/go.mod +++ b/go.mod @@ -43,7 +43,6 @@ require ( github.com/inconshreveable/mousetrap v1.0.0 // indirect github.com/klauspost/compress v1.11.7 // indirect github.com/klauspost/cpuid/v2 v2.1.0 // indirect - github.com/ktr0731/grpc-web-go-client v0.2.8 // indirect github.com/magiconair/properties v1.8.6 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect diff --git a/go.sum b/go.sum index 0c88ba8489c3a9a5d3a52ed1dded49cf417f8553..c534518a5b688f94cc4879a0acb314435fcdafb3 100644 --- a/go.sum +++ b/go.sum @@ -633,22 +633,7 @@ gitlab.com/elixxir/comms v0.0.4-0.20220913220502-eed192f654bd h1:2nHE7EoptSTBFjC gitlab.com/elixxir/comms v0.0.4-0.20220913220502-eed192f654bd/go.mod h1:AO6XkMhaHJW8eXlgL5m3UUcJqsSP8F5Wm1GX+wyq/rw= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= -gitlab.com/elixxir/crypto v0.0.7-0.20220913220142-ab0771bad0af h1:L1eOTS6m8dlCheAFOf/S3C+IcORd2R8f5qdyVRVelWA= gitlab.com/elixxir/crypto v0.0.7-0.20220913220142-ab0771bad0af/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220917193938-d5d45ca0a4d2 h1:AKmjX9Az2ArBT1HFO2rPeDX2hdpSo6/wtUEdff/ybck= -gitlab.com/elixxir/crypto v0.0.7-0.20220917193938-d5d45ca0a4d2/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220917204352-30b24e0711a2 h1:IK2ZUkvDn4+/1fnXH2TVxuacC8wzO+kgWs5mx/qBz7c= -gitlab.com/elixxir/crypto v0.0.7-0.20220917204352-30b24e0711a2/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220917212457-088250d48a3c h1:cUPyHvh3kiyv442SHECVIMA2mMr/F8Y7kxAOnu4Gde4= -gitlab.com/elixxir/crypto v0.0.7-0.20220917212457-088250d48a3c/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220919165806-fc1d25b4fd1d h1:mNqnjlfXZ3FOpr/kgRGuPZTqH59HEK4q/N6f59L7K8Q= -gitlab.com/elixxir/crypto v0.0.7-0.20220919165806-fc1d25b4fd1d/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220919170559-538d10454d07 h1:zIUAxKXpGnAejPyv4S7yVX4Zw2bA1k1BW7m3oiTqa1Y= -gitlab.com/elixxir/crypto v0.0.7-0.20220919170559-538d10454d07/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220919174648-8d1b7f5cacc4 h1:Gou55kAKhwWlK9hKFYAfOMrwgk04qpOsB5/tZa8OWlc= -gitlab.com/elixxir/crypto v0.0.7-0.20220919174648-8d1b7f5cacc4/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= -gitlab.com/elixxir/crypto v0.0.7-0.20220919221444-cb6c054c9fcd h1:uWcp0aokdBnaZhNhlbXiDYusecIP5AaFbJfBtuzEg5A= -gitlab.com/elixxir/crypto v0.0.7-0.20220919221444-cb6c054c9fcd/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= gitlab.com/elixxir/crypto v0.0.7-0.20220920002307-5541473e9aa7 h1:9IsBtL8zcUG86XcfNUVIKcnlL5tyKlyQt1cJ5nogr1U= gitlab.com/elixxir/crypto v0.0.7-0.20220920002307-5541473e9aa7/go.mod h1:QF8SzsrYh9Elip9EUYUDAhPjqO9DGrrrQxYHvn+VXok= gitlab.com/elixxir/ekv v0.2.1 h1:dtwbt6KmAXG2Tik5d60iDz2fLhoFBgWwST03p7T+9Is=