fix error handling in dial function

This commit is contained in:
dd dd 2024-11-08 14:58:29 +01:00
parent ce9a3758a4
commit b41f499a36

View File

@ -29,8 +29,8 @@ type DialOptions struct {
func DialSocks( func DialSocks(
options DialOptions, options DialOptions,
config *config.EntryConfig, config *config.EntryConfig,
) func(ctx context.Context, net_, addr string) (net.Conn, error) { ) func(ctx context.Context, _, addr string) (net.Conn, error) {
return func(ctx context.Context, net_, addr string) (net.Conn, error) { return func(ctx context.Context, _, addr string) (net.Conn, error) {
key := nostr.GeneratePrivateKey() key := nostr.GeneratePrivateKey()
connection := NewConnection(ctx, connection := NewConnection(ctx,
WithPrivateKey(key), WithPrivateKey(key),
@ -66,10 +66,30 @@ func DialSocks(
} }
opts = append(opts, protocol.WithDestination(addr)) opts = append(opts, protocol.WithDestination(addr))
ev, err := signer.CreateSignedEvent(publicKey, protocol.KindEphemeralEvent, err = createAndPublish(ctx, signer, publicKey, opts, relays, options)
if err != nil {
return nil, fmt.Errorf("error publishing event: %w", err)
}
return connection, nil
}
}
func createAndPublish(
ctx context.Context,
signer *protocol.EventSigner,
publicKey string,
opts []protocol.MessageOption,
relays []string,
options DialOptions,
) error {
ev, err := signer.CreateSignedEvent(
publicKey,
protocol.KindEphemeralEvent,
nostr.Tags{nostr.Tag{"p", publicKey}}, nostr.Tags{nostr.Tag{"p", publicKey}},
opts...) opts...)
if err != nil {
return fmt.Errorf("error creating signed event: %w", err)
}
for _, relayUrl := range relays { for _, relayUrl := range relays {
var relay *nostr.Relay var relay *nostr.Relay
relay, err = options.Pool.EnsureRelay(relayUrl) relay, err = options.Pool.EnsureRelay(relayUrl)
@ -79,9 +99,8 @@ func DialSocks(
} }
err = relay.Publish(ctx, ev) err = relay.Publish(ctx, ev)
if err != nil { if err != nil {
return nil, fmt.Errorf("error publishing event: %w", err) return fmt.Errorf("error publishing event: %w", err)
} }
} }
return connection, nil return nil
}
} }