egress

package
v0.1.5259 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 13 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 user can name the ways out they allow instead, regions and addresses (settings ClaudeWaysOut, mamba on Discord).

The lookup asks Cloudflare's trace page (TraceURL) through the same proxy, and reads its ip= and loc= lines. 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 (Keep); while the hold is on, a request also looks again once the last lookup is older than Fresh (Hold), as a node switched inside a proxy app changes nothing magpie can watch. 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 a lookup may be before Hold looks again, and
	// HoldTimeout how long that lookup, which a request waits on, may
	// take.
	Every       = 15 * time.Minute
	Poll        = 20 * time.Second
	Fresh       = 30 * time.Second
	HoldTimeout = 5 * 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 outside the supported regions, or the ways out the user allowed. A lookup older than Fresh is made again first, within HoldTimeout and shared by the requests that come meanwhile: a proxy turned back on lets the next request go, and a node switched to another country inside a proxy app holds it. 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.

One Keep looks up at a time in a process (keeping): the gateway starts one, and so does the window, whose page shows the lookups of its own process; a window that serves no gateway (another magpie does: the service, magpie serve) had none, and its Claude editor read "Not looked up yet" until Check (mamba on Discord). A second waits, and takes over when the first ends.

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
	IP    string `json:"ip,omitempty"`  // the address the lookup came from
	// Mine says the state was judged by the user's own ways out
	// (ClaudeWaysOut), not by Anthropic's list.
	Mine  bool      `json:"mine,omitempty"`
	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, judged by the ways out allowed now; 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