Skip to content

Commit

Permalink
Add initial support for recepient verification
Browse files Browse the repository at this point in the history
Not staged for the next release due to being blocked by text wrapping bug in Fyne dialogs.
  • Loading branch information
Jacalz committed Aug 7, 2021
1 parent 026e47c commit 4986c14
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
9 changes: 9 additions & 0 deletions internal/transport/bridge/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ func (p *SendList) OnFileSelect(file fyne.URIReadCloser, err error) {

go func(i int) {
defer func() {
p.client.VerifierOk = nil
if err = file.Close(); err != nil {
fyne.LogError("Error on closing file", err)
}
Expand Down Expand Up @@ -126,6 +127,10 @@ func (p *SendList) OnDirSelect(dir fyne.ListableURI, err error) {
p.NewSendItem(dir.Name(), dir)

go func(i int) {
defer func() {
p.client.VerifierOk = nil
}()

code, result, err := p.client.NewDirSend(dir, p.Items[i].Progress.update)
if err != nil {
fyne.LogError("Error on sending directory", err)
Expand All @@ -151,6 +156,10 @@ func (p *SendList) SendText() {
p.NewSendItem("Text Snippet", storage.NewFileURI("text")) // The file URI is a hack to get the correct icon

go func(i int) {
defer func() {
p.client.VerifierOk = nil
}()

if text := <-p.client.ShowTextSendWindow(); text != "" {
code, result, err := p.client.NewTextSend(text, p.Items[i].Progress.update)
if err != nil {
Expand Down
7 changes: 7 additions & 0 deletions internal/transport/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ func (c *Client) NewReceive(code string, pathname chan string) (err error) {
pathname <- pathToSend
}()

if c.Verify {
c.VerifierOk = c.VerifyRecv
defer func() {
c.VerifierOk = nil
}()
}

msg, err := c.Receive(context.Background(), code)
if err != nil {
fyne.LogError("Error on receiving data", err)
Expand Down
12 changes: 12 additions & 0 deletions internal/transport/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,19 @@ import (

// NewFileSend takes the chosen file and sends it using wormhole-william.
func (c *Client) NewFileSend(file fyne.URIReadCloser, progress wormhole.SendOption) (string, chan wormhole.SendResult, error) {
if c.Verify {
c.VerifierOk = c.VerifySend
}

return c.SendFile(context.Background(), file.URI().Name(), file.(io.ReadSeeker), progress)
}

// NewDirSend takes a listable URI and sends it using wormhole-william.
func (c *Client) NewDirSend(dir fyne.ListableURI, progress wormhole.SendOption) (string, chan wormhole.SendResult, error) {
if c.Verify {
c.VerifierOk = c.VerifySend
}

prefixStr, _ := filepath.Split(dir.Path())
prefix := len(prefixStr) // Where the prefix ends. Doing it this way is faster and works when paths don't use same separator (\ or /).

Expand Down Expand Up @@ -47,5 +55,9 @@ func (c *Client) NewDirSend(dir fyne.ListableURI, progress wormhole.SendOption)

// NewTextSend takes a text input and sends the text using wormhole-william.
func (c *Client) NewTextSend(text string, progress wormhole.SendOption) (string, chan wormhole.SendResult, error) {
if c.Verify {
c.VerifierOk = c.VerifySend
}

return c.SendText(context.Background(), text, progress)
}
20 changes: 20 additions & 0 deletions internal/transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"path/filepath"

"fyne.io/fyne/v2"
"fyne.io/fyne/v2/dialog"
"github.com/psanford/wormhole-william/wormhole"
)

Expand All @@ -19,6 +20,9 @@ type Client struct {
// Notification holds the settings value for if we have notifications enabled or not.
Notifications bool

// Verify holds information about if verification should be enabled or not.
Verify bool

// OverwriteExisting holds the settings value for if we should overwrite already existing files.
OverwriteExisting bool

Expand All @@ -33,6 +37,22 @@ func (c *Client) ShowNotification(title, content string) {
}
}

// VerifySend asks the user to verify that the verification code is correct.
func (c *Client) VerifySend(input string) bool {
verified := make(chan bool)
dialog.ShowConfirm("Verify validation", "Is "+input+" the validation code?", func(accept bool) {
verified <- accept
}, fyne.CurrentApp().Driver().AllWindows()[0])

return <-verified
}

// VerifyRecv shows the verification code that should be compared on the other end.
func (c *Client) VerifyRecv(input string) bool {
dialog.ShowInformation("Validation", "Your validation code is: "+input, fyne.CurrentApp().Driver().AllWindows()[0])
return true
}

// NewClient returns a new client for sending and receiving using wormhole-william
func NewClient() *Client {
return &Client{display: createTextWindow()}
Expand Down
19 changes: 16 additions & 3 deletions internal/ui/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ type settings struct {
overwriteFiles *widget.RadioGroup
notificationRadio *widget.RadioGroup

componentSlider *widget.Slider
componentLabel *widget.Label
componentSlider *widget.Slider
componentLabel *widget.Label
verifyRadio *widget.RadioGroup

appID *widget.Entry
rendezvousURL *widget.Entry
transitRelayAddress *widget.Entry
Expand Down Expand Up @@ -83,6 +85,11 @@ func (s *settings) onComponentsChange(value float64) {
s.componentLabel.SetText(strconv.Itoa(int(value)))
}

func (s *settings) onVerifyChanged(selected string) {
s.client.Verify = selected == "On"
s.app.Preferences().SetString("Verify", selected)
}

func (s *settings) onAppIDChanged(appID string) {
s.client.AppID = appID
s.app.Preferences().SetString("AppID", appID)
Expand Down Expand Up @@ -113,6 +120,9 @@ func (s *settings) buildUI() *container.Scroll {
s.componentSlider, s.componentLabel = &widget.Slider{Min: 2.0, Max: 6.0, Step: 1, OnChanged: s.onComponentsChange}, &widget.Label{}
s.componentSlider.SetValue(s.app.Preferences().FloatWithFallback("ComponentLength", 2))

s.verifyRadio = &widget.RadioGroup{Options: onOffOptions, Horizontal: true, Required: true, OnChanged: s.onVerifyChanged}
s.verifyRadio.SetSelected(s.app.Preferences().StringWithFallback("Verify", "Off"))

s.appID = &widget.Entry{PlaceHolder: wormhole.WormholeCLIAppID, OnChanged: s.onAppIDChanged}
s.appID.SetText(s.app.Preferences().String("AppID"))

Expand All @@ -133,7 +143,10 @@ func (s *settings) buildUI() *container.Scroll {
)

wormholeContainer := container.NewVBox(
container.NewGridWithColumns(2, newBoldLabel("Passphrase Length"), container.NewBorder(nil, nil, nil, s.componentLabel, s.componentSlider)),
container.NewGridWithColumns(2,
newBoldLabel("Passphrase Length"), container.NewBorder(nil, nil, nil, s.componentLabel, s.componentSlider),
newBoldLabel("Verify"), s.verifyRadio,
),
&widget.Accordion{Items: []*widget.AccordionItem{
{Title: "Advanced", Detail: container.NewGridWithColumns(2,
newBoldLabel("AppID"), s.appID,
Expand Down

0 comments on commit 4986c14

Please sign in to comment.