Skip to content
Snippets Groups Projects
Commit 89b98513 authored by Jono Wenger's avatar Jono Wenger
Browse files

Update file transfer examples for changes to NewManager

parent 4f645baa
No related branches found
No related tags found
No related merge requests found
...@@ -4,9 +4,9 @@ go 1.17 ...@@ -4,9 +4,9 @@ go 1.17
require ( require (
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/client v1.5.1-0.20220706193049-a0b718049663 gitlab.com/elixxir/client v1.5.1-0.20220725224450-9068bb702293
gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea
gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6 gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e
) )
require ( require (
......
...@@ -254,8 +254,8 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm ...@@ -254,8 +254,8 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40=
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/client v1.5.1-0.20220706193049-a0b718049663 h1:7bhDI2jg/aKkYNGiSsFUGkDykb1H43/+5mBCEvmnkjA= gitlab.com/elixxir/client v1.5.1-0.20220725224450-9068bb702293 h1:RJX27KLhVu/ulF/DaZCB+wNz7IFISD3hyQxlL7mP2z8=
gitlab.com/elixxir/client v1.5.1-0.20220706193049-a0b718049663/go.mod h1:GCevkp2aa+vpIsSrlF/HsRlTjf107jgCglZ/0JKqW7E= gitlab.com/elixxir/client v1.5.1-0.20220725224450-9068bb702293/go.mod h1:dRCeFJrIj5zuxSfcnsAYOCodyPrKVparJUREBIWKRcw=
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 h1:Zid8oNHtbOqF6ebrcGIccvIMabFNGh9dzY1b7mgIcF0= gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 h1:Zid8oNHtbOqF6ebrcGIccvIMabFNGh9dzY1b7mgIcF0=
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326/go.mod h1:tlHSrtSliKWUxsck8z/Ql/VJkMdSONV2BeWaUAAXzgk= gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326/go.mod h1:tlHSrtSliKWUxsck8z/Ql/VJkMdSONV2BeWaUAAXzgk=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
...@@ -289,8 +289,9 @@ gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVk ...@@ -289,8 +289,9 @@ gitlab.com/xx_network/primitives v0.0.2/go.mod h1:cs0QlFpdMDI6lAo61lDRH2JZz+3aVk
gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE= gitlab.com/xx_network/primitives v0.0.4-0.20220222211843-901fa4a2d72b/go.mod h1:9imZHvYwNFobxueSvVtHneZLk9wTK7HQTzxPm+zhFhE=
gitlab.com/xx_network/primitives v0.0.4-0.20220317172007-4d2a53e6e669/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo= gitlab.com/xx_network/primitives v0.0.4-0.20220317172007-4d2a53e6e669/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo=
gitlab.com/xx_network/primitives v0.0.4-0.20220324193139-b292d1ae6e7e/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo= gitlab.com/xx_network/primitives v0.0.4-0.20220324193139-b292d1ae6e7e/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo=
gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6 h1:3It6ILDHn/9J/Oi7MfMjkidKPe7vbFCy5JQtXx8EfYM=
gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo= gitlab.com/xx_network/primitives v0.0.4-0.20220630163313-7890038258c6/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo=
gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e h1:zRRo/v3KUo3MtpjNJaB03LR+Zi2g1afYF8yKWl1t19o=
gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e/go.mod h1:AXVVFt7dDAeIUpOGPiStCcUIKsBXLWbmV/BgZ4T+tOo=
gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93 h1:eJZrXqHsMmmejEPWw8gNAt0I8CGAMNO/7C339Zco3TM= gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93 h1:eJZrXqHsMmmejEPWw8gNAt0I8CGAMNO/7C339Zco3TM=
gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM= gitlab.com/xx_network/ring v0.0.3-0.20220222211904-da613960ad93/go.mod h1:aLzpP2TiZTQut/PVHR40EJAomzugDdHXetbieRClXIM=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
...@@ -298,6 +299,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= ...@@ -298,6 +299,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA=
......
...@@ -101,8 +101,7 @@ func main() { ...@@ -101,8 +101,7 @@ func main() {
// xxdk.DefaultAuthCallbacks is fine here // xxdk.DefaultAuthCallbacks is fine here
params := xxdk.GetDefaultE2EParams() params := xxdk.GetDefaultE2EParams()
jww.INFO.Printf("Using E2E parameters: %+v", params) jww.INFO.Printf("Using E2E parameters: %+v", params)
messenger, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{}, user, err := xxdk.Login(net, xxdk.DefaultAuthCallbacks{}, identity, params)
identity, params)
if err != nil { if err != nil {
jww.FATAL.Panicf("Unable to Login: %+v", err) jww.FATAL.Panicf("Unable to Login: %+v", err)
} }
...@@ -111,7 +110,7 @@ func main() { ...@@ -111,7 +110,7 @@ func main() {
// Set networkFollowerTimeout to a value of your choice (seconds) // Set networkFollowerTimeout to a value of your choice (seconds)
networkFollowerTimeout := 5 * time.Second networkFollowerTimeout := 5 * time.Second
err = messenger.StartNetworkFollower(networkFollowerTimeout) err = user.StartNetworkFollower(networkFollowerTimeout)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to start network follower: %+v", err) jww.FATAL.Panicf("Failed to start network follower: %+v", err)
} }
...@@ -137,7 +136,7 @@ func main() { ...@@ -137,7 +136,7 @@ func main() {
connected := make(chan bool, 10) connected := make(chan bool, 10)
// Provide a callback that will be signalled when network // Provide a callback that will be signalled when network
// health status changes // health status changes
messenger.GetCmix().AddHealthCallback( user.GetCmix().AddHealthCallback(
func(isConnected bool) { func(isConnected bool) {
connected <- isConnected connected <- isConnected
}) })
...@@ -163,7 +162,7 @@ func main() { ...@@ -163,7 +162,7 @@ func main() {
jww.INFO.Printf("Recipient contact: %+v", recipientContact) jww.INFO.Printf("Recipient contact: %+v", recipientContact)
// Create the connection // Create the connection
handler, err := connect.Connect(recipientContact, messenger, params) handler, err := connect.Connect(recipientContact, user, params)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to create connection object: %+v", err) jww.FATAL.Panicf("Failed to create connection object: %+v", err)
} }
...@@ -174,15 +173,14 @@ func main() { ...@@ -174,15 +173,14 @@ func main() {
// Create general file transfer manager // Create general file transfer manager
ftParams := fileTransfer.DefaultParams() ftParams := fileTransfer.DefaultParams()
ftManager, err := fileTransfer.NewManager(ftParams, identity.ID, ftManager, err := fileTransfer.NewManager(ftParams, user)
messenger.GetCmix(), messenger.GetStorage(), messenger.GetRng())
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err) jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err)
} }
err = messenger.AddService(ftManager.StartProcesses) err = user.AddService(ftManager.StartProcesses)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to start file transfer pcoesses: %+v", err) jww.FATAL.Panicf("Failed to start file transfer possesses: %+v", err)
} }
// Create ReceiveCallback that is called when a new file transfer is received // Create ReceiveCallback that is called when a new file transfer is received
...@@ -214,7 +212,7 @@ func main() { ...@@ -214,7 +212,7 @@ func main() {
// Wrap the file transfer in the connection wrapper // Wrap the file transfer in the connection wrapper
ftConnectParams := ftConnect.DefaultParams() ftConnectParams := ftConnect.DefaultParams()
ftWrapper, err := ftConnect.NewWrapper( ftWrapper, err := ftConnect.NewWrapper(
receiveCB, ftConnectParams, ftManager, handler, messenger.GetCmix()) receiveCB, ftConnectParams, ftManager, handler, user.GetCmix())
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err) jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err)
} }
...@@ -245,9 +243,14 @@ func main() { ...@@ -245,9 +243,14 @@ func main() {
// allows for half the parts to be resent on failure. // allows for half the parts to be resent on failure.
retryRate := float32(1.5) retryRate := float32(1.5)
// Period is the duration to wait between calls to the progress callback.
// This prevents spamming of the progress callback when many updates occur
// in a short period of time.
period := 1 * time.Millisecond
// Send file // Send file
tid, err := ftWrapper.Send(recipientContact.ID, fileName, fileType, tid, err := ftWrapper.Send(
fileData, retryRate, preview, progressCB, 0) fileName, fileType, fileData, retryRate, preview, progressCB, period)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to send file: %+v", err) jww.FATAL.Panicf("Failed to send file: %+v", err)
} }
...@@ -260,7 +263,7 @@ func main() { ...@@ -260,7 +263,7 @@ func main() {
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c <-c
err = messenger.StopNetworkFollower() err = user.StopNetworkFollower()
if err != nil { if err != nil {
jww.ERROR.Printf("Failed to stop network follower: %+v", err) jww.ERROR.Printf("Failed to stop network follower: %+v", err)
} else { } else {
......
...@@ -4,7 +4,7 @@ go 1.17 ...@@ -4,7 +4,7 @@ go 1.17
require ( require (
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
gitlab.com/elixxir/client v1.5.1-0.20220713213756-95ed0fc8e7cf gitlab.com/elixxir/client v1.5.1-0.20220725224450-9068bb702293
gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea gitlab.com/elixxir/crypto v0.0.7-0.20220606201132-c370d5039cea
gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e gitlab.com/xx_network/primitives v0.0.4-0.20220712193914-aebd8544396e
) )
......
...@@ -254,8 +254,8 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm ...@@ -254,8 +254,8 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f h1:yXGvNBqzZwAhDYlSnxPRbgor6JWoOt1Z7s3z1O9JR40=
gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k= gitlab.com/elixxir/bloomfilter v0.0.0-20211222005329-7d931ceead6f/go.mod h1:H6jztdm0k+wEV2QGK/KYA+MY9nj9Zzatux/qIvDDv3k=
gitlab.com/elixxir/client v1.5.1-0.20220713213756-95ed0fc8e7cf h1:mt92NfMLwhOharsKlN2dZE3NTPwBgOC4IchdtZjcfhQ= gitlab.com/elixxir/client v1.5.1-0.20220725224450-9068bb702293 h1:RJX27KLhVu/ulF/DaZCB+wNz7IFISD3hyQxlL7mP2z8=
gitlab.com/elixxir/client v1.5.1-0.20220713213756-95ed0fc8e7cf/go.mod h1:dRCeFJrIj5zuxSfcnsAYOCodyPrKVparJUREBIWKRcw= gitlab.com/elixxir/client v1.5.1-0.20220725224450-9068bb702293/go.mod h1:dRCeFJrIj5zuxSfcnsAYOCodyPrKVparJUREBIWKRcw=
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 h1:Zid8oNHtbOqF6ebrcGIccvIMabFNGh9dzY1b7mgIcF0= gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326 h1:Zid8oNHtbOqF6ebrcGIccvIMabFNGh9dzY1b7mgIcF0=
gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326/go.mod h1:tlHSrtSliKWUxsck8z/Ql/VJkMdSONV2BeWaUAAXzgk= gitlab.com/elixxir/comms v0.0.4-0.20220603231314-e47e4af13326/go.mod h1:tlHSrtSliKWUxsck8z/Ql/VJkMdSONV2BeWaUAAXzgk=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
...@@ -299,6 +299,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= ...@@ -299,6 +299,7 @@ go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw=
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA= go.uber.org/ratelimit v0.2.0 h1:UQE2Bgi7p2B85uP5dC2bbRtig0C+OeNRnNEafLjsLPA=
......
...@@ -103,22 +103,76 @@ func main() { ...@@ -103,22 +103,76 @@ func main() {
// Save the contact file so that client can connect to this server // Save the contact file so that client can connect to this server
writeContact(contactFilePath, identity.GetContact()) writeContact(contactFilePath, identity.GetContact())
// Handle incoming connections and create file transfer manager------------ // Handle incoming connections---------------------------------------------
// When a channel is received, a new file transfer wrapper will be created
// to wait for new file transfers
connectionCh := make(chan connect.Connection, 10)
// Create callback for incoming connections // Create callback for incoming connections
cb := func(connection connect.Connection) { cb := func(connection connect.Connection) {
connectionCh <- connection
}
// Start connection server-------------------------------------------------
// Start the connection server, which will allow clients to start
// connections with you
connectServer, err := connect.StartServer(
identity, cb, net, e2eParams, connectionListParams)
if err != nil {
jww.FATAL.Panicf("Unable to start connection server: %+v", err)
}
// Start network threads---------------------------------------------------
// Set networkFollowerTimeout to a value of your choice (seconds)
networkFollowerTimeout := 5 * time.Second
err = connectServer.User.StartNetworkFollower(networkFollowerTimeout)
if err != nil {
jww.FATAL.Panicf("Failed to start network follower: %+v", err)
}
// Set up a wait for the network to be connected
waitUntilConnected := func(connected chan bool) {
waitTimeout := 30 * time.Second
timeoutTimer := time.NewTimer(waitTimeout)
isConnected := false
// Wait until we connect or panic if we cannot before the timeout
for !isConnected {
select {
case isConnected = <-connected:
jww.INFO.Printf("Network Status: %v", isConnected)
break
case <-timeoutTimer.C:
jww.FATAL.Panicf("Timeout on starting network follower")
}
}
}
// Create a tracker channel to be notified of network changes
connected := make(chan bool, 10)
// Provide a callback that will be signalled when network health
// status changes
connectServer.User.GetCmix().AddHealthCallback(
func(isConnected bool) {
connected <- isConnected
})
// Wait until connected or crash on timeout
waitUntilConnected(connected)
// Create file transfer manager--------------------------------------------
// Create general file transfer manager // Create general file transfer manager
ftParams := fileTransfer.DefaultParams() ftParams := fileTransfer.DefaultParams()
ftManager, err := fileTransfer.NewManager(ftParams, identity.ID, ftManager, err := fileTransfer.NewManager(ftParams, connectServer.User)
net.GetCmix(), net.GetStorage(), net.GetRng())
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err) jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err)
} }
err = net.AddService(ftManager.StartProcesses) err = net.AddService(ftManager.StartProcesses)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to start file transfer pcoesses: %+v", err) jww.FATAL.Panicf("Failed to start file transfer possesses: %+v", err)
} }
// Create ReceiveCallback that is called when a new file transfer is received // Create ReceiveCallback that is called when a new file transfer is received
...@@ -150,15 +204,22 @@ func main() { ...@@ -150,15 +204,22 @@ func main() {
} }
} }
// Period is the duration to wait between calls to the progress
// callback. This prevents spamming of the progress callback when
// many updates occur in a short period of time.
period := 1 * time.Millisecond
// Register received progress callback // Register received progress callback
err = ftManager.RegisterReceivedProgressCallback( err = ftManager.RegisterReceivedProgressCallback(
tid, receivedProgressCB, 0) tid, receivedProgressCB, period)
if err != nil { if err != nil {
jww.FATAL.Panicf( jww.FATAL.Panicf(
"Failed to register received progress callback: %+v", err) "Failed to register received progress callback: %+v", err)
} }
} }
select {
case connection := <-connectionCh:
// Wrap the file transfer in the connection wrapper // Wrap the file transfer in the connection wrapper
ftConnectParams := ftConnect.DefaultParams() ftConnectParams := ftConnect.DefaultParams()
_, err = ftConnect.NewWrapper( _, err = ftConnect.NewWrapper(
...@@ -166,56 +227,10 @@ func main() { ...@@ -166,56 +227,10 @@ func main() {
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err) jww.FATAL.Panicf("Failed to create file transfer manager: %+v", err)
} }
case <-time.After(5 * time.Minute):
} jww.FATAL.Panicf("Failed to receive connection.")
// Start connection server-------------------------------------------------
// Start the connection server, which will allow clients to start
// connections with you
connectServer, err := connect.StartServer(
identity, cb, net, e2eParams, connectionListParams)
if err != nil {
jww.FATAL.Panicf("Unable to start connection server: %+v", err)
}
// Start network threads---------------------------------------------------
// Set networkFollowerTimeout to a value of your choice (seconds)
networkFollowerTimeout := 5 * time.Second
err = connectServer.E2e.StartNetworkFollower(networkFollowerTimeout)
if err != nil {
jww.FATAL.Panicf("Failed to start network follower: %+v", err)
}
// Set up a wait for the network to be connected
waitUntilConnected := func(connected chan bool) {
waitTimeout := 30 * time.Second
timeoutTimer := time.NewTimer(waitTimeout)
isConnected := false
// Wait until we connect or panic if we cannot before the timeout
for !isConnected {
select {
case isConnected = <-connected:
jww.INFO.Printf("Network Status: %v", isConnected)
break
case <-timeoutTimer.C:
jww.FATAL.Panicf("Timeout on starting network follower")
}
}
} }
// Create a tracker channel to be notified of network changes
connected := make(chan bool, 10)
// Provide a callback that will be signalled when network health
// status changes
connectServer.E2e.GetCmix().AddHealthCallback(
func(isConnected bool) {
connected <- isConnected
})
// Wait until connected or crash on timeout
waitUntilConnected(connected)
// Keep app running to receive messages------------------------------------ // Keep app running to receive messages------------------------------------
// Wait until the user terminates the program // Wait until the user terminates the program
...@@ -223,7 +238,7 @@ func main() { ...@@ -223,7 +238,7 @@ func main() {
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
<-c <-c
err = connectServer.E2e.StopNetworkFollower() err = connectServer.User.StopNetworkFollower()
if err != nil { if err != nil {
jww.ERROR.Printf("Failed to stop network follower: %+v", err) jww.ERROR.Printf("Failed to stop network follower: %+v", err)
} else { } else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment