egress

package
v0.1.4792 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package egress finds where this computer's way out to the internet is, through each proxy a Claude subscription's requests go through, and says when it is in a region Anthropic doesn't list as supported (Supported): a proxy that dropped, a VPN turned off, a node in the wrong country (@alterxyz4 on X asked for this "canary").

The lookup asks Cloudflare's trace page (TraceURL) through the same proxy, and reads its loc= line. It never touches Anthropic or the user's account. It runs when magpie starts, when the network or a proxy setting changes, and every Every, never per request (Keep). A lookup that fails says nothing: its state is Unknown, which neither warns nor holds.

Index

Constants

View Source
const (
	OK          = "ok"          // in a supported region
	Unsupported = "unsupported" // in a region the policy doesn't list
	Unknown     = "unknown"     // not looked up, or the lookup failed
)

The states a way out can be in.

View Source
const HeldWords = "magpie held this Claude request"

HeldWords begin every HeldError's text; the gateway reads them as a request that never left (nobody rests for it).

Variables

View Source
var (
	// Every is how often each choice is looked up again with nothing
	// changed; Poll how often Keep looks for a change of network or
	// proxy; Fresh how old an Unsupported may be before Hold looks again.
	Every = 15 * time.Minute
	Poll  = 20 * time.Second
	Fresh = 30 * time.Second
)

Client sends the lookup. http.DefaultClient goes through netproxy (netproxy.Install), so the choice With names is the proxy it takes.

View Source
var Supported = map[string]string{}/* 185 elements not displayed */

Supported is Anthropic's Supported Regions Policy (https://www.anthropic.com/supported-countries, effective 2026-11-12, read 2026-11-21): every country and region it lists, by ISO 3166-1 code, with the name the page gives. testdata/supported-regions.txt is the page's list as it was read, and a test holds this map to it.

View Source
var Timeout = 10 * time.Second

Timeout is how long one lookup may take.

View Source
var TraceURL = "https://www.cloudflare.com/cdn-cgi/trace"

TraceURL is the page asked; a test points it at its own server.

Functions

func Again

func Again()

Again has Keep look every choice up again now (the GUI's Check again).

func Forget

func Forget()

Forget drops every lookup kept (a test's cleanup).

func Hold

func Hold(ctx context.Context, choice string) error

Hold is the error a Claude subscription's request through choice is held with: when the user turned the hold on (settings ClaudeRegionHold) and the way out through choice is in an unsupported region. An Unsupported older than Fresh is looked up again first, so a proxy turned back on lets the next request go. Unknown holds nothing.

func Keep

func Keep(ctx context.Context, choices func() []string)

Keep looks up the way out through each of choices() when it starts, when the network or a proxy changes, every Every, and when Again asks, until ctx ends. choices is asked each Poll: the distinct proxy choices the Claude accounts' requests take; none, nothing is looked up.

func OnChange

func OnChange(f func())

OnChange has f called after a lookup changes what a choice's state is.

Types

type HeldError

type HeldError struct{ Result Result }

HeldError is a request Hold kept from going out.

func (*HeldError) Error

func (e *HeldError) Error() string

type Result

type Result struct {
	State string    `json:"state"`
	Loc   string    `json:"loc,omitempty"` // ISO 3166-1 code, as Cloudflare names it
	At    time.Time `json:"at,omitempty"`
	Error string    `json:"error,omitempty"`
	// Via is the proxy it went through, as magpie may show it
	// (netproxy.Redact): "" for the global one, "direct" for none.
	Via string `json:"via,omitempty"`
}

Result is what the last lookup through one proxy choice found.

func Check

func Check(ctx context.Context, choice string) Result

Check looks up the way out through choice now, and keeps what it found.

func Of

func Of(choice string) Result

Of is the last lookup through choice; Unknown when there was none.

func Worst

func Worst(choices []string) Result

Worst is the result of choices to show: the first Unsupported, else the first Unknown, else an OK (one of each choice's being fine).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL