Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

var (
cfgFile string
dataDir string
cfgFile string
dataDir string
connTimeout int
)

// rootCmd represents the base command when called without any subcommands
Expand Down
3 changes: 2 additions & 1 deletion cmd/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ messages can be piped into this command.`,
return nil
},
Run: func(cmd *cobra.Command, args []string) {
brbrclient.Send(dataDir, args[0])
brbrclient.Send(dataDir, args[0], connTimeout)
},
}

func init() {
sendCmd.Flags().IntVarP(&connTimeout, "timeout", "t", 60, "Specify connection timeout in seconds")
rootCmd.AddCommand(sendCmd)
}
8 changes: 5 additions & 3 deletions lib/brbrclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"google.golang.org/protobuf/types/known/timestamppb"
)

func Send(dataDir, rcptAddr string) {
func Send(dataDir, rcptAddr string, timeout int) {
var rcptId, msg string

if strings.HasSuffix(rcptAddr, ".onion") {
Expand Down Expand Up @@ -57,7 +57,9 @@ func Send(dataDir, rcptAddr string) {

msg = strings.Join(msgLines, "\n")

ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
connTimeout := time.Duration(timeout) * time.Second

ctx, cancel := context.WithTimeout(context.Background(), connTimeout)
defer cancel()

// use embedded tor (only on linux)
Expand All @@ -80,7 +82,7 @@ func Send(dataDir, rcptAddr string) {
//}
//defer t.Close()

log.Printf("Connecting to onion service %s", rcptAddr)
log.Printf("Connecting to onion service %s (timeout: %s)", rcptAddr, connTimeout)

dialer, err := t.Dialer(ctx, nil)
if err != nil {
Expand Down