2016-05-04 07:03:36 +00:00
|
|
|
package libnmdc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2017-11-14 05:45:06 +00:00
|
|
|
"fmt"
|
2016-05-04 07:03:36 +00:00
|
|
|
"net"
|
2016-10-08 02:19:21 +00:00
|
|
|
"strconv"
|
2016-05-04 07:03:36 +00:00
|
|
|
"strings"
|
2016-05-08 00:33:49 +00:00
|
|
|
"sync"
|
2016-05-04 07:03:36 +00:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
type HubConnection struct {
|
|
|
|
// Supplied parameters
|
|
|
|
Hco *HubConnectionOptions
|
|
|
|
|
|
|
|
// Current remote status
|
2016-05-08 00:33:49 +00:00
|
|
|
HubName string
|
|
|
|
State ConnectionState
|
|
|
|
users map[string]UserInfo
|
|
|
|
userLock sync.RWMutex
|
2016-05-04 07:03:36 +00:00
|
|
|
|
|
|
|
// Streamed events
|
|
|
|
processEvent func(HubEvent)
|
|
|
|
OnEvent chan HubEvent
|
|
|
|
|
|
|
|
// Private state
|
2017-11-14 05:45:06 +00:00
|
|
|
conn net.Conn // this is an interface
|
|
|
|
connValid bool
|
|
|
|
sentOurHello bool
|
|
|
|
autoReconnect bool
|
|
|
|
lastDataRecieved time.Time
|
2017-02-08 06:22:07 +00:00
|
|
|
|
|
|
|
supports map[string]struct{}
|
2016-05-04 07:03:36 +00:00
|
|
|
}
|
|
|
|
|
2016-11-29 06:49:53 +00:00
|
|
|
// Thread-safe user accessor.
|
2016-05-08 00:33:49 +00:00
|
|
|
func (this *HubConnection) Users(cb func(*map[string]UserInfo) error) error {
|
|
|
|
this.userLock.Lock()
|
|
|
|
defer this.userLock.Unlock()
|
|
|
|
|
|
|
|
return cb(&this.users)
|
|
|
|
}
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
func (this *HubConnection) SayPublic(message string) {
|
2016-11-29 06:44:10 +00:00
|
|
|
this.SayRaw("<" + this.Hco.Self.Nick + "> " + Escape(message) + "|")
|
2016-05-04 07:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HubConnection) SayPrivate(recipient string, message string) {
|
2016-11-29 06:44:10 +00:00
|
|
|
this.SayRaw("$To: " + recipient + " From: " + this.Hco.Self.Nick + " $<" + this.Hco.Self.Nick + "> " + Escape(message) + "|")
|
2016-05-04 07:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HubConnection) SayInfo() {
|
|
|
|
this.SayRaw(this.Hco.Self.toMyINFO() + "|")
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:33:49 +00:00
|
|
|
func (this *HubConnection) UserExists(nick string) bool {
|
|
|
|
this.userLock.RLock()
|
|
|
|
defer this.userLock.RUnlock()
|
|
|
|
|
|
|
|
_, already_existed := this.users[nick]
|
|
|
|
return already_existed
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:37:05 +00:00
|
|
|
func (this *HubConnection) UserCount() int {
|
|
|
|
this.userLock.RLock()
|
|
|
|
defer this.userLock.RUnlock()
|
|
|
|
|
|
|
|
return len(this.users)
|
|
|
|
}
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
func (this *HubConnection) userJoined_NameOnly(nick string) {
|
2016-05-08 00:33:49 +00:00
|
|
|
if !this.UserExists(nick) {
|
|
|
|
|
2017-02-05 06:06:17 +00:00
|
|
|
this.userLock.Lock()
|
2016-05-08 00:33:49 +00:00
|
|
|
this.users[nick] = *NewUserInfo(nick)
|
2017-02-05 06:06:17 +00:00
|
|
|
this.userLock.Unlock() // Don't lock over a processEvent boundary
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_JOINED, Nick: nick})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HubConnection) userJoined_Full(uinf *UserInfo) {
|
2016-08-27 03:31:00 +00:00
|
|
|
// n.b. also called when we get a replacement MyINFO for someone
|
|
|
|
this.userLock.Lock()
|
|
|
|
_, userExisted := this.users[uinf.Nick] // don't use UserExists as it would deadlock the mutex
|
|
|
|
this.users[uinf.Nick] = *uinf
|
2017-02-05 06:06:17 +00:00
|
|
|
this.userLock.Unlock() // Don't lock over a processEvent boundary
|
2016-05-08 00:33:49 +00:00
|
|
|
|
2016-08-27 03:31:00 +00:00
|
|
|
if !userExisted {
|
2016-05-04 07:03:36 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_JOINED, Nick: uinf.Nick})
|
2017-02-08 05:58:14 +00:00
|
|
|
} else {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: uinf.Nick})
|
2016-05-04 07:03:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 06:49:53 +00:00
|
|
|
// SayRaw sends raw bytes over the TCP socket. Callers should add the protocol
|
|
|
|
// terminating character `|` themselves.
|
2016-05-04 07:03:36 +00:00
|
|
|
// Note that protocol messages are transmitted on the caller thread, not from
|
|
|
|
// any internal libnmdc thread.
|
|
|
|
func (this *HubConnection) SayRaw(protocolCommand string) error {
|
|
|
|
if this.connValid {
|
|
|
|
_, err := this.conn.Write([]byte(protocolCommand))
|
|
|
|
return err
|
|
|
|
} else {
|
|
|
|
return ErrNotConnected
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (this *HubConnection) processProtocolMessage(message string) {
|
|
|
|
|
|
|
|
// Zero-length protocol message
|
|
|
|
// ````````````````````````````
|
|
|
|
if len(message) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Public chat
|
|
|
|
// ```````````
|
|
|
|
if rx_publicChat.MatchString(message) {
|
|
|
|
pubchat_parts := rx_publicChat.FindStringSubmatch(message)
|
2016-11-29 06:44:10 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_PUBLIC, Nick: pubchat_parts[1], Message: Unescape(pubchat_parts[2])})
|
2016-05-04 07:03:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// System messages
|
|
|
|
// ```````````````
|
|
|
|
if message[0] != '$' {
|
2016-11-29 06:44:10 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_HUB, Nick: this.HubName, Message: Unescape(message)})
|
2016-05-04 07:03:36 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// Protocol messages
|
|
|
|
// `````````````````
|
|
|
|
|
|
|
|
commandParts := strings.SplitN(message, " ", 2)
|
|
|
|
switch commandParts[0] {
|
|
|
|
|
|
|
|
case "$Lock":
|
2017-02-08 06:30:53 +00:00
|
|
|
this.SayRaw("$Supports NoHello NoGetINFO UserCommand UserIP2 QuickList ChatOnly|" +
|
2017-02-08 06:22:07 +00:00
|
|
|
"$Key " + unlock([]byte(commandParts[1])) + "|")
|
2016-05-04 07:03:36 +00:00
|
|
|
this.sentOurHello = false
|
|
|
|
|
|
|
|
case "$Hello":
|
|
|
|
if commandParts[1] == this.Hco.Self.Nick && !this.sentOurHello {
|
|
|
|
this.SayRaw("$Version 1,0091|")
|
|
|
|
this.SayRaw("$GetNickList|")
|
|
|
|
this.SayInfo()
|
|
|
|
this.sentOurHello = true
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.userJoined_NameOnly(commandParts[1])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$HubName":
|
|
|
|
this.HubName = commandParts[1]
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_HUBNAME_CHANGED, Nick: commandParts[1]})
|
|
|
|
|
|
|
|
case "$ValidateDenide": // sic
|
|
|
|
if len(this.Hco.NickPassword) > 0 {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Incorrect password."})
|
|
|
|
} else {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Nick already in use."})
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$HubIsFull":
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Hub is full."})
|
|
|
|
|
|
|
|
case "$BadPass":
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "Incorrect password."})
|
|
|
|
|
|
|
|
case "$GetPass":
|
2017-02-05 04:12:59 +00:00
|
|
|
if len(this.Hco.NickPassword) == 0 {
|
|
|
|
// We've got a problem. MyPass with no arguments is a syntax error with no message = instant close
|
|
|
|
// Just drop the connection
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_SYSTEM_MESSAGE_FROM_CONN, Message: "This account is passworded."})
|
|
|
|
this.Disconnect()
|
|
|
|
} else {
|
|
|
|
this.SayRaw("$MyPass " + Escape(this.Hco.NickPassword) + "|")
|
|
|
|
}
|
2016-05-04 07:03:36 +00:00
|
|
|
|
|
|
|
case "$Quit":
|
2017-02-05 06:06:17 +00:00
|
|
|
this.userLock.Lock()
|
|
|
|
delete(this.users, commandParts[1])
|
|
|
|
this.userLock.Unlock() // Don't lock over a processEvent boundary
|
2016-05-08 00:33:49 +00:00
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_PART, Nick: commandParts[1]})
|
|
|
|
|
|
|
|
case "$MyINFO":
|
|
|
|
u := UserInfo{}
|
|
|
|
err := u.fromMyINFO(commandParts[1])
|
2017-02-08 05:57:49 +00:00
|
|
|
if err != nil {
|
2016-05-04 07:03:36 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: err.Error()})
|
2017-02-08 05:57:49 +00:00
|
|
|
return
|
2016-05-04 07:03:36 +00:00
|
|
|
}
|
|
|
|
|
2017-02-08 05:57:49 +00:00
|
|
|
this.userJoined_Full(&u)
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
case "$NickList":
|
|
|
|
nicklist := strings.Split(commandParts[1], "$$")
|
|
|
|
for _, nick := range nicklist {
|
|
|
|
if len(nick) > 0 {
|
|
|
|
this.userJoined_NameOnly(nick)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-08 00:49:36 +00:00
|
|
|
case "$OpList":
|
|
|
|
oplist := strings.Split(commandParts[1], "$$")
|
|
|
|
opmap := map[string]struct{}{}
|
|
|
|
|
|
|
|
// Organise/sort the list, and ensure we're not meeting an operator for
|
|
|
|
// the first time
|
|
|
|
for _, nick := range oplist {
|
|
|
|
if len(nick) > 0 {
|
|
|
|
opmap[nick] = struct{}{}
|
|
|
|
this.userJoined_NameOnly(nick) // assert existence; noop otherwise
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mark all mentioned nicks as being operators, and all unmentioned nicks
|
|
|
|
// as being /not/ an operator. (second pass minimises RW mutex use)
|
|
|
|
func() {
|
|
|
|
this.userLock.Lock()
|
|
|
|
defer this.userLock.Unlock()
|
|
|
|
|
|
|
|
for nick, userinfo := range this.users {
|
|
|
|
_, isop := opmap[nick]
|
|
|
|
|
|
|
|
userinfo.IsOperator = isop
|
|
|
|
this.users[nick] = userinfo
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
case "$To:":
|
|
|
|
valid := false
|
|
|
|
if rx_incomingTo.MatchString(commandParts[1]) {
|
|
|
|
txparts := rx_incomingTo.FindStringSubmatch(commandParts[1])
|
|
|
|
if txparts[1] == this.Hco.Self.Nick && txparts[2] == txparts[3] {
|
2016-11-29 06:44:10 +00:00
|
|
|
this.processEvent(HubEvent{EventType: EVENT_PRIVATE, Nick: txparts[2], Message: Unescape(txparts[4])})
|
2016-05-04 07:03:36 +00:00
|
|
|
valid = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !valid {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed private message '" + commandParts[1] + "'"})
|
|
|
|
}
|
|
|
|
|
|
|
|
case "$UserIP":
|
2017-02-09 06:28:37 +00:00
|
|
|
this.userLock.Lock()
|
|
|
|
|
|
|
|
pairs := strings.Split(commandParts[1], "$$")
|
|
|
|
notifyOfUpdate := make([]string, 0, len(pairs))
|
|
|
|
|
|
|
|
nextIPPair:
|
|
|
|
for _, pair := range pairs {
|
|
|
|
parts := strings.SplitN(pair, " ", 2)
|
2017-02-11 00:55:20 +00:00
|
|
|
if len(parts) != 2 {
|
|
|
|
// ????
|
|
|
|
continue nextIPPair
|
|
|
|
}
|
|
|
|
|
2017-02-09 06:28:37 +00:00
|
|
|
ip2nick := parts[0]
|
|
|
|
ip2addr := parts[1]
|
|
|
|
|
|
|
|
uinfo, ok := this.users[ip2nick]
|
|
|
|
if !ok {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Recieved IP '" + ip2addr + "' for unknown user '" + ip2nick + "'"})
|
|
|
|
continue nextIPPair
|
|
|
|
}
|
|
|
|
|
|
|
|
if uinfo.IPAddress != ip2addr {
|
|
|
|
uinfo.IPAddress = ip2addr
|
|
|
|
notifyOfUpdate = append(notifyOfUpdate, ip2nick)
|
|
|
|
this.users[ip2nick] = uinfo
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.userLock.Unlock()
|
|
|
|
|
|
|
|
for _, nick := range notifyOfUpdate {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USER_UPDATED_INFO, Nick: nick})
|
|
|
|
}
|
2016-05-04 07:03:36 +00:00
|
|
|
|
|
|
|
case "$ForceMove":
|
|
|
|
this.Hco.Address = HubAddress(commandParts[1])
|
|
|
|
this.conn.Close() // we'll reconnect onto the new address
|
|
|
|
|
2016-10-08 02:19:21 +00:00
|
|
|
case "$UserCommand":
|
|
|
|
// $UserCommand 1 1 Group chat\New group chat$<%[mynick]> !groupchat_new||
|
|
|
|
if rx_userCommand.MatchString(commandParts[1]) {
|
|
|
|
usc := rx_userCommand.FindStringSubmatch(commandParts[1])
|
|
|
|
|
|
|
|
typeInt, _ := strconv.Atoi(usc[1])
|
|
|
|
contextInt, _ := strconv.Atoi(usc[2])
|
|
|
|
|
|
|
|
uscStruct := UserCommand{
|
|
|
|
Type: UserCommandType(typeInt),
|
|
|
|
Context: UserCommandContext(contextInt),
|
|
|
|
Message: usc[3],
|
2016-11-29 06:44:10 +00:00
|
|
|
Command: Unescape(usc[4]),
|
2016-10-08 02:19:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_USERCOMMAND, UserCommand: &uscStruct})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Malformed usercommand '" + commandParts[1] + "'"})
|
|
|
|
}
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
case "$Supports":
|
2017-02-08 06:22:07 +00:00
|
|
|
this.supports = make(map[string]struct{})
|
|
|
|
for _, s := range strings.Split(commandParts[1], " ") {
|
|
|
|
this.supports[s] = struct{}{}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !this.sentOurHello {
|
|
|
|
|
|
|
|
// Need to log in.
|
|
|
|
// If the hub supports QuickList, we can skip one network roundtrip
|
|
|
|
if _, ok := this.supports["QuickList"]; ok {
|
|
|
|
this.SayInfo()
|
|
|
|
this.SayRaw("$GetNickList|")
|
|
|
|
} else {
|
|
|
|
this.SayRaw("$ValidateNick " + Escape(this.Hco.Self.Nick) + "|")
|
|
|
|
}
|
|
|
|
|
2017-02-09 06:19:17 +00:00
|
|
|
// This also counts as the end of the handshake from our POV. Consider
|
|
|
|
// ourselves logged in
|
|
|
|
this.sentOurHello = true
|
|
|
|
if this.State != CONNECTIONSTATE_CONNECTED {
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTED})
|
|
|
|
this.State = CONNECTIONSTATE_CONNECTED
|
|
|
|
}
|
|
|
|
|
2017-02-08 06:22:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IGNORABLE COMMANDS
|
2016-05-04 07:03:36 +00:00
|
|
|
case "$HubTopic":
|
|
|
|
case "$Search":
|
|
|
|
case "$ConnectToMe":
|
|
|
|
|
|
|
|
default:
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_DEBUG_MESSAGE, Message: "Unhandled protocol command '" + commandParts[0] + "'"})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-04 07:17:20 +00:00
|
|
|
func (this *HubConnection) Disconnect() {
|
|
|
|
this.autoReconnect = false
|
|
|
|
if this.conn != nil {
|
|
|
|
this.conn.Close()
|
|
|
|
}
|
|
|
|
// A CONNECTIONSTATE_DISCONNECTED message will be emitted by the worker.
|
|
|
|
}
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
func (this *HubConnection) worker() {
|
|
|
|
var fullBuffer string
|
|
|
|
var err error = nil
|
|
|
|
var nbytes int = 0
|
|
|
|
|
|
|
|
for {
|
|
|
|
|
|
|
|
// If we're not connected, attempt reconnect
|
|
|
|
if this.conn == nil {
|
|
|
|
|
|
|
|
fullBuffer = "" // clear
|
|
|
|
|
|
|
|
if this.Hco.Address.IsSecure() {
|
|
|
|
this.conn, err = tls.Dial("tcp", this.Hco.Address.GetHostOnly(), &tls.Config{
|
|
|
|
InsecureSkipVerify: this.Hco.SkipVerifyTLS,
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.conn, err = net.Dial("tcp", this.Hco.Address.GetHostOnly())
|
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
this.State = CONNECTIONSTATE_DISCONNECTED
|
|
|
|
this.connValid = false
|
|
|
|
|
|
|
|
} else {
|
|
|
|
this.State = CONNECTIONSTATE_CONNECTING
|
|
|
|
this.connValid = true
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_CONNECTING})
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read from socket into our local buffer (blocking)
|
|
|
|
if this.connValid {
|
|
|
|
readBuff := make([]byte, 1024)
|
|
|
|
this.conn.SetReadDeadline(time.Now().Add(SEND_KEEPALIVE_EVERY))
|
|
|
|
nbytes, err = this.conn.Read(readBuff)
|
|
|
|
|
2016-11-29 06:43:32 +00:00
|
|
|
if checkIsNetTimeout(err) {
|
2016-05-04 07:03:36 +00:00
|
|
|
// No data before read deadline
|
|
|
|
err = nil
|
|
|
|
|
|
|
|
// Send KA packet
|
|
|
|
_, err = this.conn.Write([]byte("|"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if nbytes > 0 {
|
2017-11-14 05:45:06 +00:00
|
|
|
this.lastDataRecieved = time.Now()
|
2016-05-04 07:03:36 +00:00
|
|
|
fullBuffer += string(readBuff[0:nbytes])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to parse a message block
|
|
|
|
for len(fullBuffer) > 0 {
|
|
|
|
for len(fullBuffer) > 0 && fullBuffer[0] == '|' {
|
|
|
|
fullBuffer = fullBuffer[1:]
|
|
|
|
}
|
|
|
|
protocolMessage := rx_protocolMessage.FindString(fullBuffer)
|
|
|
|
if len(protocolMessage) > 0 {
|
|
|
|
this.processProtocolMessage(protocolMessage[:len(protocolMessage)-1])
|
|
|
|
fullBuffer = fullBuffer[len(protocolMessage):]
|
|
|
|
} else {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-14 05:45:06 +00:00
|
|
|
if err == nil && time.Now().Sub(this.lastDataRecieved) > RECONNECT_IF_NO_DATA_RECIEVED_IN {
|
|
|
|
err = fmt.Errorf("No packets recieved since %s, connection presumed lost", this.lastDataRecieved.Format(time.RFC3339))
|
|
|
|
}
|
|
|
|
|
2016-05-04 07:03:36 +00:00
|
|
|
// Maybe we disconnected
|
|
|
|
// Perform this check *last*, to ensure we've had a final shot at
|
|
|
|
// clearing out any queued messages
|
|
|
|
if err != nil {
|
|
|
|
this.State = CONNECTIONSTATE_DISCONNECTED
|
|
|
|
this.conn = nil
|
|
|
|
this.connValid = false
|
|
|
|
this.processEvent(HubEvent{EventType: EVENT_CONNECTION_STATE_CHANGED, StateChange: CONNECTIONSTATE_DISCONNECTED, Message: err.Error()})
|
|
|
|
|
2016-05-04 07:15:02 +00:00
|
|
|
if this.autoReconnect {
|
|
|
|
time.Sleep(AUTO_RECONNECT_AFTER) // Wait before reconnect
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
return // leave the worker for good
|
|
|
|
}
|
2016-05-04 07:03:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|