improve use bind of stream start + logging
This commit is contained in:
parent
3c13b83657
commit
940d328b09
|
@ -86,7 +86,7 @@ func (client *Client) auth(password string) error {
|
||||||
if mechanism == "" {
|
if mechanism == "" {
|
||||||
return fmt.Errorf("PLAIN authentication is not an option: %s", f.Mechanisms.Mechanism)
|
return fmt.Errorf("PLAIN authentication is not an option: %s", f.Mechanisms.Mechanism)
|
||||||
}
|
}
|
||||||
client.Logging.Info("used auth with '%s'", mechanism)
|
client.Logging.Infof("used auth with '%s'", mechanism)
|
||||||
|
|
||||||
element, err := client.Read()
|
element, err := client.Read()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -42,8 +42,14 @@ func (client *Client) startStream() (*messages.StreamFeatures, error) {
|
||||||
debug += " tls"
|
debug += " tls"
|
||||||
}
|
}
|
||||||
debug += " mechanism("
|
debug += " mechanism("
|
||||||
|
mFirst := true
|
||||||
for _, m := range f.Mechanisms.Mechanism {
|
for _, m := range f.Mechanisms.Mechanism {
|
||||||
debug += m
|
if mFirst {
|
||||||
|
mFirst = false
|
||||||
|
debug += m
|
||||||
|
} else {
|
||||||
|
debug += ", " + m
|
||||||
|
}
|
||||||
}
|
}
|
||||||
debug += ")"
|
debug += ")"
|
||||||
if f.Bind != nil {
|
if f.Bind != nil {
|
||||||
|
@ -81,41 +87,47 @@ func (client *Client) connect(password string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := client.startStream(); err != nil {
|
f, err := client.startStream()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// bind to resource
|
bind := f.Bind
|
||||||
bind := &messages.Bind{}
|
if f.Bind == nil || (f.Bind.JID == nil && f.Bind.Resource == "") {
|
||||||
if client.JID.Resource != "" {
|
// bind to resource
|
||||||
bind.Resource = client.JID.Resource
|
if client.JID.Resource != "" {
|
||||||
}
|
bind.Resource = client.JID.Resource
|
||||||
if err := client.Send(&messages.IQClient{
|
|
||||||
Type: messages.IQTypeSet,
|
|
||||||
To: model.NewJID(client.JID.Domain),
|
|
||||||
Bind: bind,
|
|
||||||
}); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var iq messages.IQClient
|
|
||||||
if err := client.ReadDecode(&iq); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if iq.Error != nil {
|
|
||||||
if iq.Error.ServiceUnavailable == nil {
|
|
||||||
return errors.New(fmt.Sprintf("recv error on iq>bind: %s[%s]: %s -> %s -> %s", iq.Error.Code, iq.Error.Type, iq.Error.Text, messages.XMLChildrenString(iq.Error.StanzaErrorGroup), messages.XMLChildrenString(iq.Error.Other)))
|
|
||||||
} else {
|
|
||||||
client.Logging.Warn("connected without setting resource with bind after auth: service-unavailable")
|
|
||||||
}
|
}
|
||||||
} else if iq.Bind == nil {
|
if err := client.Send(&messages.IQClient{
|
||||||
return errors.New("<iq> result missing <bind>")
|
Type: messages.IQTypeSet,
|
||||||
} else if iq.Bind.JID != nil {
|
To: model.NewJID(client.JID.Domain),
|
||||||
client.JID.Local = iq.Bind.JID.Local
|
Bind: bind,
|
||||||
client.JID.Domain = iq.Bind.JID.Domain
|
}); err != nil {
|
||||||
client.JID.Resource = iq.Bind.JID.Resource
|
return err
|
||||||
client.Logging.Info("set resource by server bind")
|
}
|
||||||
|
|
||||||
|
var iq messages.IQClient
|
||||||
|
if err := client.ReadDecode(&iq); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if iq.Error != nil {
|
||||||
|
return errors.New(fmt.Sprintf("recv error on iq>bind: %s[%s]: %s -> %s -> %s", iq.Error.Code, iq.Error.Type, iq.Error.Text, messages.XMLChildrenString(iq.Error.StanzaErrorGroup), messages.XMLChildrenString(iq.Error.Other)))
|
||||||
|
} else if iq.Bind == nil {
|
||||||
|
return errors.New("iq>bind is nil :" + messages.XMLChildrenString(iq.Other))
|
||||||
|
}
|
||||||
|
bind = iq.Bind
|
||||||
|
}
|
||||||
|
if bind == nil {
|
||||||
|
return errors.New("bind is nil")
|
||||||
|
} else if bind.JID != nil {
|
||||||
|
client.JID.Local = bind.JID.Local
|
||||||
|
client.JID.Domain = bind.JID.Domain
|
||||||
|
client.JID.Resource = bind.JID.Resource
|
||||||
|
client.Logging.Infof("set jid by server bind '%s'", bind.JID.Full())
|
||||||
|
} else if bind.Resource != "" {
|
||||||
|
client.JID.Resource = bind.Resource
|
||||||
|
client.Logging.Infof("set resource by server bind '%s'", bind.Resource)
|
||||||
} else {
|
} else {
|
||||||
return errors.New(messages.XMLChildrenString(iq.Other))
|
return errors.New("bind>jid is nil" + messages.XMLChildrenString(bind))
|
||||||
}
|
}
|
||||||
// set status
|
// set status
|
||||||
return client.Send(&messages.PresenceClient{Show: messages.PresenceShowXA, Status: "online"})
|
return client.Send(&messages.PresenceClient{Show: messages.PresenceShowXA, Status: "online"})
|
||||||
|
|
|
@ -112,10 +112,10 @@ func (t *Tester) StartBot(status *Status) {
|
||||||
for _, jid := range t.Admins {
|
for _, jid := range t.Admins {
|
||||||
if first {
|
if first {
|
||||||
first = false
|
first = false
|
||||||
|
allAdmins += jid.Bare()
|
||||||
} else {
|
} else {
|
||||||
allAdmins += ", "
|
allAdmins += ", " + jid.Bare()
|
||||||
}
|
}
|
||||||
allAdmins += jid.Bare()
|
|
||||||
if jid.Bare() == msg.From.Bare() {
|
if jid.Bare() == msg.From.Bare() {
|
||||||
isAdmin = true
|
isAdmin = true
|
||||||
status.client.Send(messages.MessageClient{Type: msg.Type, To: jid, Body: "last message, disconnect requested by " + msg.From.Bare()})
|
status.client.Send(messages.MessageClient{Type: msg.Type, To: jid, Body: "last message, disconnect requested by " + msg.From.Bare()})
|
||||||
|
|
|
@ -23,7 +23,7 @@ func XMLStartElementToString(element *xml.StartElement) string {
|
||||||
}
|
}
|
||||||
debug := fmt.Sprintf("<%s xmlns=\"%s\"", element.Name.Local, element.Name.Space)
|
debug := fmt.Sprintf("<%s xmlns=\"%s\"", element.Name.Local, element.Name.Space)
|
||||||
for _, attr := range element.Attr {
|
for _, attr := range element.Attr {
|
||||||
debug = fmt.Sprintf("%s %s=\"%s\"", debug, attr.Name, attr.Value)
|
debug = fmt.Sprintf("%s %s=\"%s\"", debug, attr.Name.Local, attr.Value)
|
||||||
}
|
}
|
||||||
debug += ">"
|
debug += ">"
|
||||||
return debug
|
return debug
|
||||||
|
@ -54,10 +54,10 @@ func XMLChildrenString(o interface{}) (result string) {
|
||||||
if xmlElement, ok := valueField.Interface().(*xml.Name); ok && xmlElement != nil {
|
if xmlElement, ok := valueField.Interface().(*xml.Name); ok && xmlElement != nil {
|
||||||
if first {
|
if first {
|
||||||
first = false
|
first = false
|
||||||
|
result += xmlElement.Local
|
||||||
} else {
|
} else {
|
||||||
result += ", "
|
result += ", " + xmlElement.Local
|
||||||
}
|
}
|
||||||
result += xmlElement.Local
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
tlsdir = "tmp/ssl"
|
accounts_path = "tmp/yaja-tester.json"
|
||||||
state_path = "tmp/yaja-tester.json"
|
output_path = "tmp/yaja-tester-output.json"
|
||||||
logging = 5
|
|
||||||
|
|
||||||
webserver = ":https"
|
logging = 4
|
||||||
|
logging_clients = 4
|
||||||
|
logging_bots = 3
|
||||||
|
|
||||||
|
interval = "30s"
|
||||||
|
timeout = "10s"
|
||||||
|
|
||||||
admins = ["a.admin@chat.sum7.eu"]
|
admins = ["a.admin@chat.sum7.eu"]
|
||||||
|
|
||||||
|
|
Reference in New Issue