Skip to content
Snippets Groups Projects
Commit 8b230ecf authored by Jonah Husson's avatar Jonah Husson
Browse files

Add text output for integration

parent 384985a3
Branches
Tags
2 merge requests!510Release,!240Integration update, allow client to use both broadcast methods
......@@ -13,6 +13,7 @@ import (
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/utils"
"os"
"sync"
"time"
)
......@@ -83,6 +84,7 @@ var broadcastCmd = &cobra.Command{
} else {
fmt.Printf("Private key generated for channel: %+v", rsa.CreatePrivateKeyPem(pk))
}
fmt.Printf("New broadcast channel generated")
} else {
// Read rest of info from config & build object manually
pubKeyBytes := []byte(viper.GetString("rsaPub"))
......@@ -176,22 +178,35 @@ var broadcastCmd = &cobra.Command{
/* Broadcast messages to the channel */
if symmetric != "" || asymmetric != "" {
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
jww.INFO.Printf("Attempting to send broadcasts...")
// Wait for sendDelay before sending (to allow connection to establish)
sendDelay := time.Duration(viper.GetUint("sendDelay"))
time.Sleep(sendDelay)
maxRetries := 10
retries := 0
for {
// Wait for sendDelay before sending (to allow connection to establish)
if maxRetries == retries {
jww.FATAL.Panicf("Max retries reached")
}
time.Sleep(sendDelay*time.Millisecond*time.Duration(retries) + 1)
/* Send symmetric broadcast */
if symmetric != "" {
// Create properly sized broadcast message
broadcastMessage, err := broadcast.NewSizedBroadcast(bcl.MaxPayloadSize(), []byte(symmetric))
if err != nil {
jww.ERROR.Printf("Failed to create sized broadcast: %+v", err)
jww.FATAL.Panicf("Failed to create sized broadcast: %+v", err)
}
rid, eid, err := bcl.Broadcast(broadcastMessage, cmix.GetDefaultCMIXParams())
if err != nil {
jww.FATAL.Panicf("Failed to send symmetric broadcast message: %+v", err)
jww.ERROR.Printf("Failed to send symmetric broadcast message: %+v", err)
retries++
continue
}
fmt.Printf("Sent symmetric broadcast message: %s", symmetric)
jww.INFO.Printf("Sent symmetric broadcast message to %s over round %d", eid, rid)
}
......@@ -200,17 +215,27 @@ var broadcastCmd = &cobra.Command{
// Create properly sized broadcast message
broadcastMessage, err := broadcast.NewSizedBroadcast(bcl.MaxAsymmetricPayloadSize(), []byte(asymmetric))
if err != nil {
jww.ERROR.Printf("Failed to create sized broadcast: %+v", err)
jww.FATAL.Panicf("Failed to create sized broadcast: %+v", err)
}
if pk == nil {
jww.FATAL.Panicf("CANNOT SEND ASYMMETRIC BROADCAST WITHOUT PRIVATE KEY")
}
rid, eid, err := bcl.BroadcastAsymmetric(pk, broadcastMessage, cmix.GetDefaultCMIXParams())
if err != nil {
jww.FATAL.Panicf("Failed to send asymmetric broadcast message: %+v", err)
jww.ERROR.Printf("Failed to send asymmetric broadcast message: %+v", err)
retries++
continue
}
fmt.Printf("Sent asymmetric broadcast message: %s", asymmetric)
jww.INFO.Printf("Sent asymmetric broadcast message to %s over round %d", eid, rid)
}
wg.Done()
break
}
}()
wg.Wait()
}
/* Receive broadcast messages over the channel */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment