package iroh

import (
	
	

	
)

// HandshakeRejectError rejects a completed handshake with an application close
// code and reason.
type HandshakeRejectError struct {
	Code   uint64
	Reason string
}

// Error implements error.
func ( *HandshakeRejectError) () string {
	return fmt.Sprintf("reject handshake: code %d: %s", .Code, .Reason)
}

// RejectHandshake rejects a completed handshake with code and reason.
func ( uint64,  string) error {
	return &HandshakeRejectError{Code: , Reason: }
}

// EndpointHooks observes and can reject an endpoint's outbound dials and its
// completed handshakes.
type EndpointHooks interface {
	// BeforeConnect runs before an outbound dial. Returning an error abandons
	// the dial and the error reaches the caller of [Endpoint.Connect]. It does
	// not run for accepted connections.
	BeforeConnect(ctx context.Context, addr netaddr.EndpointAddr, alpn string) error

	// AfterHandshake runs once for every connection the endpoint establishes,
	// dialed and accepted alike; [Conn.Side] distinguishes them. A hook
	// installed on a server therefore fires for connections it never dialed.
	// Returning an error closes the connection; use [RejectHandshake] to pick
	// the close code and reason.
	//
	// For a dialed connection it runs on the goroutine establishing it, with
	// that caller's context. For an accepted connection it runs on a goroutine
	// of its own, with the context of the accept loop ([Router],
	// [StreamListener]) or of the endpoint ([Endpoint.Accept]), so a slow hook
	// delays only the connection it is judging. On the 0-RTT paths
	// ([Connecting.Into0RTT] and early-data accepts) the handshake
	// completes after the connection is already in use, so AfterHandshake runs
	// on a separate goroutine with a background context: a hook that touches
	// shared state must be safe for concurrent use.
	AfterHandshake(ctx context.Context, conn *Conn) error
}

type noopHooks struct{}

func (noopHooks) (context.Context, netaddr.EndpointAddr, string) error { return nil }

func (noopHooks) (context.Context, *Conn) error { return nil }