@@ -128,6 +128,7 @@ var (
128128 errWsNoEntitlement = errors .New ("ws: missing entitlement" )
129129 errWsNoToken = errors .New ("ws: missing token" )
130130 errWsNoCid = errors .New ("ws: missing cid" )
131+ errWsNoDid = errors .New ("ws: missing device id" )
131132 errWsNoResponse = errors .New ("ws: no response" )
132133 errWsNoLocHash = errors .New ("ws: no loc hash" )
133134 errWsNoServerList = errors .New ("ws: no server list" )
@@ -702,6 +703,7 @@ type WsWgConfig struct {
702703type WsEntitlement struct {
703704 Kind string `json:"kind"` // e.g. "ws#v1"
704705 Cid string `json:"cid"` // Client ID
706+ Did string `json:"did,omitempty"` // Device ID, if any
705707 Pid string `json:"pid,omitempty"` // Share ID
706708 SessionToken string `json:"sessiontoken"` // Encrypted session token
707709 // Expiry date of the entitlement; go.dev/play/p/d2gshytEF61
@@ -718,6 +720,10 @@ func (e *WsEntitlement) ProviderID() string {
718720 return x .RpnWin
719721}
720722
723+ func (e * WsEntitlement ) DID () string {
724+ return e .Did
725+ }
726+
721727func (e * WsEntitlement ) CID () string {
722728 return e .Cid
723729}
@@ -742,6 +748,19 @@ func (e *WsEntitlement) Test() bool {
742748 return e .TestDomain
743749}
744750
751+ func (e * WsEntitlement ) Json () ([]byte , error ) {
752+ if e == nil {
753+ return nil , errWsNoEntitlement
754+ }
755+ var w core.ByteWriter
756+ enc := json .NewEncoder (& w )
757+ if err := enc .Encode (e ); err != nil {
758+ return nil , fmt .Errorf ("ws: entitlement encode err: %w" , err )
759+ }
760+ // Bytes not recycled as these are crossing into cgo
761+ return w .Bytes (), nil
762+ }
763+
745764func (a * WsWgConfig ) Json () ([]byte , error ) {
746765 if a == nil {
747766 return nil , errWsNoConfig
@@ -751,7 +770,7 @@ func (a *WsWgConfig) Json() ([]byte, error) {
751770 if err := a .writeJson (& w ); err != nil {
752771 return nil , err
753772 }
754- // Bytes not recycled
773+ // Bytes not recycled as these are crossing into cgo
755774 return w .Bytes (), nil
756775}
757776
@@ -1539,17 +1558,21 @@ func newWsGw(c *WsWgConfig, h *http.Client) (*WsClient, error) {
15391558 return a , nil
15401559}
15411560
1542- func (w * BaseClient ) MakeWsWg (entitlement []byte ) (* WsClient , error ) {
1561+ func (w * BaseClient ) MakeWsWg (entitlement []byte , did string ) (* WsClient , error ) {
15431562 if len (entitlement ) <= 0 {
15441563 return nil , errWsNoEntitlement
15451564 }
1565+ if len (did ) <= 0 {
1566+ return nil , errWsNoDid
1567+ }
15461568
15471569 var ent WsEntitlement
15481570 err := json .Unmarshal (entitlement , & ent )
15491571 if err != nil {
15501572 return nil , err
15511573 }
15521574
1575+ (& ent ).Did = did
15531576 return makeWsWg (& w .h2 , & ent )
15541577}
15551578
@@ -1585,28 +1608,37 @@ func makeWsWg(h *http.Client, ent *WsEntitlement) (*WsClient, error) {
15851608 return newWsGw (cfg , h )
15861609}
15871610
1588- func (w * BaseClient ) MakeWsEntitlement (entitlementOrStateJson []byte ) (x.RpnEntitlement , error ) {
1611+ func (w * BaseClient ) MakeWsEntitlement (entitlementOrStateJson []byte , did string ) (x.RpnEntitlement , error ) {
15891612 if len (entitlementOrStateJson ) <= 0 {
15901613 return nil , errWsNoEntitlement
15911614 }
1615+ if len (did ) <= 0 {
1616+ return nil , errWsNoDid
1617+ }
15921618
15931619 var ent WsEntitlement
15941620 err1 := json .Unmarshal (entitlementOrStateJson , & ent )
15951621 if err1 == nil {
1622+ (& ent ).Did = did
15961623 return & ent , nil
15971624 }
15981625 var existingConf WsWgConfig
15991626 err2 := json .Unmarshal (entitlementOrStateJson , & existingConf )
16001627 if err2 == nil && existingConf .Entitlement != nil && len (existingConf .Entitlement .SessionToken ) > 0 {
1601- return existingConf .Entitlement , nil
1628+ ent := existingConf .Entitlement
1629+ (ent ).Did = did
1630+ return ent , nil
16021631 }
16031632 return nil , core .JoinErr (err1 , err2 )
16041633}
16051634
1606- func (w * BaseClient ) MakeWsWgFrom (entitlementOrWsConfigJson []byte ) (* WsClient , error ) {
1635+ func (w * BaseClient ) MakeWsWgFrom (entitlementOrWsConfigJson []byte , did string ) (* WsClient , error ) {
16071636 if len (entitlementOrWsConfigJson ) <= 0 {
16081637 return nil , errWsNoJsonConfig
16091638 }
1639+ if len (did ) <= 0 {
1640+ return nil , errWsNoDid
1641+ }
16101642
16111643 var existingConf WsWgConfig
16121644 err := json .Unmarshal (entitlementOrWsConfigJson , & existingConf )
@@ -1618,8 +1650,9 @@ func (w *BaseClient) MakeWsWgFrom(entitlementOrWsConfigJson []byte) (*WsClient,
16181650 // may be this is an entitlement and not conf?
16191651 log .W ("ws: make: unmarshal config (sz %d / hasEnt %t / hasTok %t) err? %v; retry as entitlement" ,
16201652 sz , hasEnt , hasTok , err )
1621- return w .MakeWsWg (entitlementOrWsConfigJson )
1653+ return w .MakeWsWg (entitlementOrWsConfigJson , did )
16221654 }
1655+ (existingConf .Entitlement ).Did = did
16231656 return w .makeWsWgFrom (& existingConf )
16241657}
16251658
0 commit comments