99 "math/rand"
1010 "net/http"
1111 "net/url"
12+ "slices"
1213 "sync"
1314
1415 "github.com/nyiyui/qrystal/coord"
@@ -29,6 +30,7 @@ type Client struct {
2930 goalHandle * goal.Handle
3031 dns dns.Client
3132 dnsLock sync.Mutex
33+ canForward bool
3234
3335 spec spec.SpecCensored
3436 token util.Token
@@ -65,6 +67,10 @@ func NewClient(httpClient *http.Client, baseURL string, token util.Token, networ
6567 }, nil
6668}
6769
70+ func (c * Client ) SetCanForward (canForward bool ) {
71+ c .canForward = canForward
72+ }
73+
6874func (c * Client ) SetDNSClient (client dns.Client ) {
6975 c .dnsLock .Lock ()
7076 defer c .dnsLock .Unlock ()
@@ -281,23 +287,25 @@ func (c *Client) patchAccessible(nc *spec.NetworkCensored) error {
281287 zap .S ().Debugf ("ndcI = %s" , ndcI )
282288
283289 var accessible []string
284- for _ , ndc := range nc .Devices {
285- if ndc .ForwarderAndEndpointChosen {
286- accessible = append (accessible , ndc .Name )
290+ if c .canForward {
291+ for _ , ndc := range nc .Devices {
292+ if ndc .ForwarderAndEndpointChosen {
293+ accessible = append (accessible , ndc .Name )
294+ }
287295 }
296+ zap .S ().Debugf ("I can forward for %d devices." , len (accessible ))
297+ } else {
298+ zap .S ().Debug ("I cannot forward by configuration." )
288299 }
289- if len (accessible ) != 0 {
300+ if ! slices . Equal (accessible , nc . Devices [ ndcI ]. Accessible ) {
290301 nc .Devices [ndcI ].Accessible = accessible
291- zap .S ().Debugf ("I can forward for %d devices." , len (accessible ))
292302 err := c .patchSpec (coord.PatchReifySpecRequest {
293303 Accessible : accessible ,
294304 AccessibleSet : true ,
295305 })
296306 if err != nil {
297307 return fmt .Errorf ("patch spec: %w" , err )
298308 }
299- } else {
300- zap .S ().Infof ("I can't forward for any devices." )
301309 }
302310 return nil
303311}
0 commit comments