code: func newState(ns *structs.NodeService, token string) (*state, error) {
  	if ns.Kind != structs.ServiceKindConnectProxy {
  		return nil, errors.New("not a connect-proxy")
  	}
  
  	// Copy the config map
  	proxyCfgRaw, err := copystructure.Copy(ns.Proxy)
  	if err != nil {
  		return nil, err
  	}
  	proxyCfg, ok := proxyCfgRaw.(structs.ConnectProxyConfig)
  	if !ok {
  		return nil, errors.New("failed to copy proxy config")
  	}
  
  	return &state{
  		proxyID:  ns.ID,
  		address:  ns.Address,
  		port:     ns.Port,
  		proxyCfg: proxyCfg,
  		token:    token,
  		// 10 is fairly arbitrary here but allow for the 3 mandatory and a
  		// reasonable number of upstream watches to all deliver their initial
  		// messages in parallel without blocking the cache.Notify loops. It's not a
  		// huge deal if we do for a short period so we don't need to be more
  		// conservative to handle larger numbers of upstreams correctly but gives
  		// some head room for normal operation to be non-blocking in most typical
  		// cases.
  		ch:     make(chan cache.UpdateEvent, 10),
  		snapCh: make(chan ConfigSnapshot, 1),
  		reqCh:  make(chan chan *ConfigSnapshot, 1),
  	}, nil
  }
docs: // newState populates the state struct by copying relevant fields from the
  // NodeService and Token. We copy so that we can use them in a separate
  // goroutine later without reasoning about races with the NodeService passed
  // (especially for embedded fields like maps and slices).
  //
  // The returned state needs it's required dependencies to be set before Watch
  // can be called.