type paramMap udpapi.ParamMap // shortcut
+type noauthAPIReply struct {
+ udpapi.APIReply
+}
+
+func (r *noauthAPIReply) Code() int {
+ return 501
+}
+
+func (r *noauthAPIReply) Text() string {
+ return "LOGIN FIRST"
+}
+
+func (r *noauthAPIReply) Error() error {
+ return &udpapi.APIError{Code: r.Code(), Desc: r.Text()}
+}
+
type bannedAPIReply struct {
udpapi.APIReply
}
return "BANNED"
}
func (r *bannedAPIReply) Error() error {
- return &udpapi.APIError{Code: 555, Desc: "BANNED"}
+ return &udpapi.APIError{Code: r.Code(), Desc: r.Text()}
}
var bannedReply udpapi.APIReply = &bannedAPIReply{}
func (udp *udpWrap) sendQueue() {
+ initialWait := 6 * time.Second
+ wait := initialWait
for set := range udp.sendQueueCh {
+ Retry:
reply := <-udp.AniDBUDP.SendRecv(set.cmd, udpapi.ParamMap(set.params))
if reply.Error() == udpapi.TimeoutError {
// retry
- go func(set paramSet) { udp.sendQueueCh <- set }(set)
- continue
+ wait = (wait * 15) / 10
+ if wait > time.Minute {
+ wait = time.Minute
+ }
+ time.Sleep(wait)
+ goto Retry
}
+ wait = initialWait
switch reply.Code() {
case 403, 501, 506: // not logged in, or session expired
if err := udp.ReAuth(); err == nil {
// retry
- go func(set paramSet) { udp.sendQueueCh <- set }(set)
- continue
+ goto Retry
}
case 503, 504: // client library rejected
panic(reply.Error())
func (udp *udpWrap) SendRecv(cmd string, params paramMap) <-chan udpapi.APIReply {
ch := make(chan udpapi.APIReply, 1)
+ if udp.credentials == nil {
+ ch <- &noauthAPIReply{}
+ close(ch)
+ return ch
+ }
if Banned() {
ch <- bannedReply