Fix context handling (#39)

This commit is contained in:
asmogo 2024-09-01 21:22:13 +02:00 committed by GitHub
parent 59ff5034f9
commit b04b4f7e10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 6 deletions

View File

@ -195,7 +195,8 @@ func (e *Exit) setSubscriptions(ctx context.Context) error {
// It returns an error if there is any issue with the subscription.
func (e *Exit) handleSubscription(ctx context.Context, pubKey string, since nostr.Timestamp) error {
incomingEventChannel := e.pool.SubMany(ctx, e.config.NostrRelays, nostr.Filters{
{Kinds: []int{protocol.KindEphemeralEvent},
{
Kinds: []int{protocol.KindEphemeralEvent},
Since: &since,
Tags: nostr.TagMap{
"p": []string{pubKey},

View File

@ -163,6 +163,9 @@ func (nc *NostrConnection) Write(b []byte) (int, error) {
// Go lang
func (nc *NostrConnection) handleNostrWrite(buffer []byte) (int, error) {
if nc.ctx.Err() != nil {
return 0, fmt.Errorf("context canceled: %w", nc.ctx.Err())
}
publicKey, relays, err := nc.parseDestination()
if err != nil {
return 0, fmt.Errorf("could not parse destination: %w", err)

View File

@ -44,7 +44,7 @@ func DialSocks(options DialOptions, config *config.EntryConfig) func(ctx context
} else {
publicKey, relays, err = connection.parseDestination()
if err != nil {
slog.Error("error parsing host", err)
slog.Error("error parsing host", "error", err)
return nil, fmt.Errorf("error parsing host: %w", err)
}
}

View File

@ -3,13 +3,15 @@ package socks5
import (
"context"
"fmt"
"github.com/asmogo/nws/netstr"
"github.com/asmogo/nws/protocol"
"github.com/google/uuid"
"io"
"net"
"strconv"
"strings"
"time"
"github.com/asmogo/nws/netstr"
"github.com/asmogo/nws/protocol"
"github.com/google/uuid"
)
const (
@ -193,7 +195,7 @@ func (s *Server) handleConnect(ctx context.Context, conn net.Conn, req *Request,
dial = netstr.DialSocks(options, s.config.entryConfig)
}
ctx, _ = context.WithTimeout(context.Background(), time.Second*10)
target, err := dial(ctx, "tcp", req.realDestAddr.Address())
if err != nil {
msg := err.Error()