mirror of
https://github.com/asmogo/nws.git
synced 2025-01-18 10:01:33 +00:00
Fix context handling (#39)
This commit is contained in:
parent
59ff5034f9
commit
b04b4f7e10
@ -195,7 +195,8 @@ func (e *Exit) setSubscriptions(ctx context.Context) error {
|
|||||||
// It returns an error if there is any issue with the subscription.
|
// 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 {
|
func (e *Exit) handleSubscription(ctx context.Context, pubKey string, since nostr.Timestamp) error {
|
||||||
incomingEventChannel := e.pool.SubMany(ctx, e.config.NostrRelays, nostr.Filters{
|
incomingEventChannel := e.pool.SubMany(ctx, e.config.NostrRelays, nostr.Filters{
|
||||||
{Kinds: []int{protocol.KindEphemeralEvent},
|
{
|
||||||
|
Kinds: []int{protocol.KindEphemeralEvent},
|
||||||
Since: &since,
|
Since: &since,
|
||||||
Tags: nostr.TagMap{
|
Tags: nostr.TagMap{
|
||||||
"p": []string{pubKey},
|
"p": []string{pubKey},
|
||||||
|
@ -163,6 +163,9 @@ func (nc *NostrConnection) Write(b []byte) (int, error) {
|
|||||||
|
|
||||||
// Go lang
|
// Go lang
|
||||||
func (nc *NostrConnection) handleNostrWrite(buffer []byte) (int, error) {
|
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()
|
publicKey, relays, err := nc.parseDestination()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("could not parse destination: %w", err)
|
return 0, fmt.Errorf("could not parse destination: %w", err)
|
||||||
|
@ -44,7 +44,7 @@ func DialSocks(options DialOptions, config *config.EntryConfig) func(ctx context
|
|||||||
} else {
|
} else {
|
||||||
publicKey, relays, err = connection.parseDestination()
|
publicKey, relays, err = connection.parseDestination()
|
||||||
if err != nil {
|
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)
|
return nil, fmt.Errorf("error parsing host: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,13 +3,15 @@ package socks5
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/asmogo/nws/netstr"
|
|
||||||
"github.com/asmogo/nws/protocol"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/asmogo/nws/netstr"
|
||||||
|
"github.com/asmogo/nws/protocol"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -193,7 +195,7 @@ func (s *Server) handleConnect(ctx context.Context, conn net.Conn, req *Request,
|
|||||||
|
|
||||||
dial = netstr.DialSocks(options, s.config.entryConfig)
|
dial = netstr.DialSocks(options, s.config.entryConfig)
|
||||||
}
|
}
|
||||||
|
ctx, _ = context.WithTimeout(context.Background(), time.Second*10)
|
||||||
target, err := dial(ctx, "tcp", req.realDestAddr.Address())
|
target, err := dial(ctx, "tcp", req.realDestAddr.Address())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := err.Error()
|
msg := err.Error()
|
||||||
|
Loading…
Reference in New Issue
Block a user