Skip to content

Commit

Permalink
dcping: initial support for redirect; fixes #89
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed May 2, 2019
1 parent f3845b6 commit 45844e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions nmdc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ func (c *Conn) TextEncoder() *encoding.Encoder {
return c.w.Encoder()
}

func (c *Conn) TextDecoder() *encoding.Decoder {
return c.r.Decoder()
}

func (c *Conn) setEncoding(enc encoding.Encoding, event bool) {
if enc != nil {
e := enc.NewEncoder()
Expand Down
12 changes: 11 additions & 1 deletion nmdc/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type HubInfo struct {
Users []nmdc.MyINFO
Ops []string
Bots []string
Redirect string
}

func (h *HubInfo) decodeWith(enc encoding.Encoding) error {
Expand Down Expand Up @@ -244,6 +245,9 @@ func Ping(ctx context.Context, addr string, conf PingConfig) (_ *HubInfo, gerr e
if listStarted || listEnd {
return &hub, nil
}
if hub.Redirect != "" {
return &hub, nil
}
if lastMsg != "" {
err = fmt.Errorf("connection closed: %s", lastMsg)
if strings.Contains(lastMsg, "registered users only") {
Expand Down Expand Up @@ -354,7 +358,13 @@ func Ping(ctx context.Context, addr string, conf PingConfig) (_ *HubInfo, gerr e
return &hub, nil
}
case *nmdc.UserIP:
// TODO: some implementations seem to end the list with this message
// TODO: some implementations seem to end the list with this message
case *nmdc.RawMessage:
// TODO: change to ForceMove type, once supported
switch msg.Typ {
case "ForceMove":
hub.Redirect = string(msg.Data)
}
}
}
}
2 changes: 2 additions & 0 deletions ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func Ping(ctx context.Context, addr string, conf *PingConfig) (*HubInfo, error)
},
Users: len(hub.Users),
UserList: make([]HubUser, 0, len(hub.Users)),
Redirect: hub.Redirect,
}
if info.Desc == "" {
info.Desc = hub.Topic
Expand Down Expand Up @@ -175,6 +176,7 @@ type HubInfo struct {
Users int `json:"users" xml:"Users,attr"`
Files uint64 `json:"files,omitempty" xml:"Files,attr,omitempty"`
Share uint64 `json:"share,omitempty" xml:"Shared,attr,omitempty"`
Redirect string `json:"redirect,omitempty" xml:"Redirect,attr,omitempty"`
UserList []HubUser `json:"userlist,omitempty" xml:"User,attr,omitempty"`
}

Expand Down

0 comments on commit 45844e2

Please sign in to comment.