Skip to content

Commit d709aeb

Browse files
ignoramousCopilot
andcommitted
ipn: impl Proxy.Client
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
1 parent be56579 commit d709aeb

File tree

6 files changed

+670
-0
lines changed

6 files changed

+670
-0
lines changed

intra/backend/ipn_proxies.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ type Proxy interface {
116116
Type() *Gostr
117117
// Returns x.Router.
118118
Router() Router
119+
// Client returns a client that uses this proxy.
120+
Client() Client
119121
// GetAddr returns the address of this proxy.
120122
GetAddr() *Gostr
121123
// DNS returns the ip:port or doh/dot url or dnscrypt stamp for this proxy.
@@ -212,6 +214,13 @@ type Router interface {
212214
Contains(ipprefix *Gostr) (y bool)
213215
}
214216

217+
type Client interface {
218+
// IP4 returns information about this client's remote IPv4.
219+
IP4() (*IPMetadata, error)
220+
// IP6 returns information about this client's remote IPv6.
221+
IP6() (*IPMetadata, error)
222+
}
223+
215224
// ProxyListener is a listener for proxy events.
216225
type ProxyListener interface {
217226
// OnProxyAdded is called when a proxy is added.
@@ -289,3 +298,28 @@ type RpnServer struct {
289298
// Number of active servers in this CC+City.
290299
Count int32
291300
}
301+
302+
type IPMetadata struct {
303+
// Proxy ID used to fetch this IP metadata.
304+
ID string
305+
// Provider that provided this IP metadata.
306+
ProviderURL string
307+
// IP address, never empty.
308+
IP string
309+
// ASN number, may be empty.
310+
ASN string
311+
// ASN organization name, may be empty.
312+
ASNOrg string
313+
// ASN domain, may be empty.
314+
ASNDom string
315+
// Country code, may be empty.
316+
CC string
317+
// City name, may be empty.
318+
City string
319+
// Address, may be empty.
320+
Addr string
321+
// Latitude, may be zero.
322+
Lat float64
323+
// Longitude, may be zero.
324+
Lon float64
325+
}

intra/ipn/ground.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type ground struct {
1919
SkipRefresh
2020
GWNoVia
2121
CantPause
22+
NoClient
2223
addr string
2324
}
2425

intra/ipn/nop.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ func (NoVia) Hop(Proxy, bool) error { return errNop }
142142

143143
var errNop = errors.New("proxy: nop")
144144

145+
type NoClient struct{}
146+
147+
func (NoClient) Client() x.Client { return nil }
148+
145149
type NoProxy struct {
146150
NoDNS
147151
ProtoAgnostic
@@ -163,3 +167,4 @@ func (NoProxy) Dialer() protect.RDialer { return n
163167
func (NoProxy) Status() int { return 0 }
164168
func (NoProxy) GetAddr() *x.Gostr { return nil }
165169
func (NoProxy) Stop() error { return nil }
170+
func (NoProxy) Client() x.Client { return nil }

0 commit comments

Comments
 (0)