@@ -13,6 +13,7 @@ import (
1313 "log"
1414 "net"
1515 "net/netip"
16+ "os"
1617 "testing"
1718 "time"
1819
@@ -114,11 +115,11 @@ type fakeBdg struct {
114115
115116var (
116117 // baseNsOpts = &x.DNSOpts{PIDCSV: dnsx.NetBaseProxy, IPCSV: "", TIDCSV: x.CT + "test0"}
117- baseTab = & x.Tab {CID : "testcid" , Block : false }
118- seNsOpts = & x.DNSOpts {PIDCSV : ipn .RpnSE , IPCSV : "" , TIDCSV : x .CT + "test0" }
118+ baseTab = & x.Tab {CID : "testcid" , Block : false }
119+ autoNsOpts = & x.DNSOpts {PIDCSV : x .RpnSE , IPCSV : "" , TIDCSV : x .CT + "test0" }
119120)
120121
121- func (* fakeBdg ) OnQuery (_ , _ string , _ int ) * x.DNSOpts { return seNsOpts }
122+ func (* fakeBdg ) OnQuery (_ , _ string , _ int ) * x.DNSOpts { return autoNsOpts }
122123func (* fakeBdg ) OnResponse (* x.DNSSummary ) {}
123124func (* fakeBdg ) OnDNSAdded (string ) {}
124125func (* fakeBdg ) OnDNSRemoved (string ) {}
@@ -252,7 +253,7 @@ func TestSEProxy(t *testing.T) {
252253 }
253254
254255 natpt := x64 .NewNatPt ()
255- resolv := dnsx .NewResolver (ctx , "10.111.222.3" , dtr , bdg , natpt )
256+ resolv := dnsx .NewResolver (ctx , "10.111.222.3:53 " , dtr , bdg , natpt )
256257 resolv .Add (tr )
257258
258259 if err := pxr .RegisterSE (); err != nil {
@@ -313,65 +314,123 @@ func TestProtonReaches(t *testing.T) {
313314 settings .Debug = true
314315 dialers .Mapper (netr )
315316
316- _ = xdns .NetAndProxyID ("tcp" , ipn .Base )
317+ _ = xdns .NetAndProxyID ("tcp" , ipn .Auto )
317318
318- tr , _ := NewTLSTransport (ctx , "test0" , "1.1.1.1 " , nil , pxr )
319+ tr , _ := NewTLSTransport (ctx , "test0" , "8.8.8.8 " , nil , pxr )
319320 dtr , _ := NewTransport (ctx , x .Default , "1.1.1.1" , "53" , pxr )
320321 if tr == nil || dtr == nil {
321322 t .Fatal ("nil dns transports" )
322323 }
323324
324325 natpt := x64 .NewNatPt ()
325- resolv := dnsx .NewResolver (ctx , "10.111.222.3" , dtr , bdg , natpt )
326+ resolv := dnsx .NewResolver (ctx , "10.111.222.3:53 " , dtr , bdg , natpt )
326327 resolv .Add (tr )
327328
328- var projson []byte
329- var err error
330- if projson , err = pxr .RegisterProton (nil ); err != nil {
329+ projson , err := os .ReadFile ("proton.json" )
330+ if err != nil {
331+ projson = nil
332+ }
333+
334+ ilog .D ("proton: read file: err? %v" , err )
335+ if projson , err = pxr .RegisterProton (projson ); err != nil {
331336 t .Fatal (err )
337+ } else {
338+ _ = os .WriteFile ("proton.json" , projson , 0644 )
339+ ilog .D ("proton: setup %d" , len (projson ))
332340 }
333- if ips , err := pxr .TestProton (); err != nil {
341+
342+ amzjson , err := os .ReadFile ("amz.json" )
343+ if err != nil {
344+ amzjson = nil
345+ }
346+
347+ ilog .D ("amz: read file: err? %v" , err )
348+ if amzjson , err = pxr .RegisterAmnezia (amzjson ); err != nil {
334349 t .Fatal (err )
335350 } else {
336- ilog .D ("se: %v" , ips )
351+ _ = os .WriteFile ("amz.json" , amzjson , 0644 )
352+ ilog .D ("amz: setup %d" , len (amzjson ))
337353 }
338354
355+ // if ips, err := pxr.TestProton(); err != nil {
356+ // t.Fatal(err)
357+ // } else {
358+ // ilog.D("se: %v", ips)
359+ // }
360+
339361 var pro warp.ProtonWgConfig
340362 if err = json .Unmarshal (projson , & pro ); err != nil {
341363 t .Fatal (err )
342364 }
343365
344- const maxVisited = 6
345- once := false
366+ const maxVisited = 10
346367 visited := make (map [string ]struct {}, 0 )
347368 for _ , c := range pro .RegionalWgConfs {
348369 if _ , ok := visited [c .CC ]; ! ok {
349- ilog .I ("adding proxy %s %s" , c .CC , c .Name )
350- _ , _ = pxr .AddProxy (ipn .RpnPro + c .CC , c .UapiConfig ())
370+ // _, _ = pxr.AddProxy(ipn.RpnPro+c.CC, c.UapiConfig())
351371 visited [c .CC ] = struct {}{}
352372 }
353- if ! once {
354- ilog .I ("adding default proxy %s" , ipn .RpnPro , c .Name )
355- pxr .AddProxy (ipn .RpnPro , c .UapiConfig ())
356- once = true
357- }
358373 if len (visited ) >= maxVisited {
359374 break
360375 }
361376 }
377+ ilog .I ("available proxy CCs (limited to 10): %v" , visited )
378+
379+ proton , err := pxr .Proton ()
380+ ko (t , err )
381+
382+ _ , err = pxr .Amnezia ()
383+ ko (t , err )
384+
385+ // _, err = proton.Fork("UK")
386+ // ko(t, err)
387+ // _, err = proton.Fork("CH")
388+ // ko(t, err)
389+ _ , err = proton .Fork ("CH" )
390+ ko (t , err )
391+
392+ settings .SetAutoDialsParallel (false )
393+ settings .SetAutoMode (settings .AutoModeRemote )
362394
363395 propx , _ := pxr .ProxyFor (ipn .RpnPro )
364- propx2 , _ := pxr .ProxyFor (ipn .RpnPro + "MX" )
365- if propx == nil || propx2 == nil {
396+ propx2 , _ := pxr .ProxyFor (ipn .RpnPro + "CH" )
397+ amzpx , _ := pxr .ProxyFor (ipn .RpnAmz )
398+ auto , _ := pxr .ProxyFor (ipn .Auto )
399+ if propx == nil || propx2 == nil || amzpx == nil || auto == nil {
366400 t .Fatal ("nil proxies" )
367401 }
368- ilog .I ("proxies 1: %t; 2: %t" , propx != nil , propx2 != nil )
402+
403+ /*ilog.VV("-----------------------MAIN--------------------------")
404+ ilog.I("proxies 1: %t; 2: %t, 3: %t", propx != nil, propx2 != nil, auto != nil)
369405 if ok := ipn.Reaches(propx, "google.com:443", "tcp"); !ok {
370406 t.Fail()
371407 }
408+ ilog.VV("-----------------------MXCO--------------------------")
372409 if ok := ipn.Reaches(propx2, "cloudflare.com:443", "tcp"); !ok {
373410 t.Fail()
374411 }
412+ ilog.VV("-----------------------AUTO--------------------------")
413+ if ok := ipn.Reaches(auto, "x.com:443", "tcp"); !ok {
414+ t.Fail()
415+ }*/
416+ ilog .VV ("-----------------------DNSX--------------------------" )
417+ b4 , _ := aquery ("skysports.com" ).Pack ()
418+ r4 , _ , err := resolv .Lookup (b4 ) // must use "test0"
419+
420+ ilog .D ("%v" , propx2 .Router ().Stat ())
421+ time .Sleep (2 * time .Second )
422+
423+ if err != nil {
424+ t .Fatal (err )
425+ }
426+
427+ ans := xdns .AsMsg (r4 )
428+ if xdns .Len (ans ) == 0 && xdns .Len (ans ) == 0 {
429+ t .Fatal ("no ans" )
430+ }
431+ ilog .D ("dns" , xdns .Ans (ans ))
432+ ilog .VV ("-----------------------END0--------------------------" )
433+
375434 t .Log ("proxy reaches" )
376435}
377436
@@ -417,3 +476,9 @@ func aaaaquery(d string) *dns.Msg {
417476 msg .Id = 3456
418477 return msg
419478}
479+
480+ func ko (t * testing.T , err error ) {
481+ if err != nil {
482+ t .Fatal (err )
483+ }
484+ }
0 commit comments