Skip to content

Commit 18c7847

Browse files
committed
fix
1 parent bd87637 commit 18c7847

265 files changed

Lines changed: 107280 additions & 106779 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

tim.DB/db.go renamed to DB/db.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import (
77
"database/sql"
88
"os"
99

10+
. "tim/common"
11+
1012
"github.com/donnie4w/go-logger/logger"
1113
_ "github.com/go-sql-driver/mysql"
12-
. "tim.common"
1314
)
1415

1516
var Master *sql.DB
File renamed without changes.
File renamed without changes.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"encoding/base64"
88
)
99

10-
func Base64Encode(src []byte) string {
10+
func Base64Encode(bs []byte) string {
1111
// return []byte(coder.EncodeToString(src))
12-
return base64.StdEncoding.EncodeToString(src)
12+
return base64.StdEncoding.EncodeToString(bs)
1313
}
1414

1515
func Base64Decode(src string) ([]byte, error) {
Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44
package client
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
910
"os"
1011
"runtime/debug"
1112
"sync"
1213
"time"
1314

14-
"git.apache.org/thrift.git/lib/go/thrift"
15+
. "tim/protocol"
16+
"tim/route"
17+
18+
"github.com/apache/thrift/lib/go/thrift"
1519
"github.com/donnie4w/go-logger/logger"
16-
. "tim.protocol"
17-
"tim.route"
1820
)
1921

2022
type FLOW string
@@ -41,6 +43,7 @@ type Connect struct {
4143
Client *ITimClient
4244
FlowConnect FLOW
4345
Super *Cli
46+
ts *thrift.TSocket
4447
}
4548

4649
func (this *Connect) Close() {
@@ -50,9 +53,9 @@ func (this *Connect) Close() {
5053
logger.Error(string(debug.Stack()))
5154
}
5255
}()
53-
if this.Client != nil && this.Client.Transport != nil && this.FlowConnect != CONNECT_STOP {
56+
if this.Client != nil && this.ts != nil && this.FlowConnect != CONNECT_STOP {
5457
this.FlowConnect = CONNECT_STOP
55-
this.Client.Transport.Close()
58+
this.ts.Close()
5659
}
5760
}
5861

@@ -200,7 +203,7 @@ func (this *Cli) SendMBean(mbean *TimMBean) (err error) {
200203
}
201204
}
202205
if this.Addr != "" {
203-
err = this.Connect.Client.TimMessage(mbean)
206+
err = this.Connect.Client.TimMessage(context.Background(), mbean)
204207
Confirm.Add(mbean.GetThreadId(), mbean)
205208
}
206209
} else {
@@ -238,7 +241,7 @@ func (this *Cli) SendPBean(pbean *TimPBean) (err error) {
238241
}
239242
}
240243
if this.Addr != "" {
241-
err = this.Connect.Client.TimPresence(pbean)
244+
err = this.Connect.Client.TimPresence(context.Background(), pbean)
242245
if err != nil {
243246
logger.Error("SendPBean error:", err.Error())
244247
}
@@ -257,7 +260,7 @@ func (this *Cli) DisConnect() {
257260
}
258261
}()
259262
if this != nil && this.Connect != nil {
260-
this.Connect.Client.Transport.Close()
263+
this.Connect.Close()
261264
}
262265
}
263266

@@ -271,7 +274,7 @@ func (this *Cli) Ack(ab *TimAckBean) {
271274
this.Sync.Lock()
272275
defer this.Sync.Unlock()
273276
if this != nil && this.Connect != nil && this.Flow == AUTH {
274-
this.Connect.Client.TimAck(ab)
277+
this.Connect.Client.TimAck(context.Background(), ab)
275278
}
276279
}
277280

@@ -284,7 +287,7 @@ func (this *Cli) Close() {
284287
}()
285288
if this != nil && this.Connect != nil {
286289
this.Flow = CLOSE
287-
this.Connect.Client.Transport.Close()
290+
this.Connect.Close()
288291
}
289292
}
290293

@@ -323,7 +326,7 @@ func (this *Cli) Ping() {
323326
logger.Debug("client ping>>>>>>>>>>>>>>>>>")
324327
this.Sync.Lock()
325328
defer this.Sync.Unlock()
326-
err = this.Connect.Client.TimPing(fmt.Sprint(currentTimeMillis()))
329+
err = this.Connect.Client.TimPing(context.Background(), fmt.Sprint(currentTimeMillis()))
327330
logger.Debug("client ping<<<<<<<<<<<<<<<<<")
328331
return
329332
}()
@@ -352,12 +355,12 @@ func (this *Cli) Login() (err error) {
352355
fmt.Fprintln(os.Stderr, "error resolving address:", err)
353356
return
354357
}
355-
useTransport := transportFactory.GetTransport(transport)
358+
useTransport, _ := transportFactory.GetTransport(transport)
356359
timclient := NewITimClientFactory(useTransport, protocolFactory)
357360
if this.Connect != nil {
358361
this.Connect.Close()
359362
}
360-
this.Connect = &Connect{FlowConnect: CONNECT_START}
363+
this.Connect = &Connect{FlowConnect: CONNECT_START, ts: transport}
361364
this.Connect.setITimClient(timclient)
362365
this.Connect.Super = this
363366
if err = transport.Open(); err != nil {
@@ -369,7 +372,7 @@ func (this *Cli) Login() (err error) {
369372
tid := new(Tid)
370373
resource := "goclient"
371374
tid.Domain, tid.Resource, tid.Name = this.Domain, &resource, this.Name
372-
err = timclient.TimLogin(tid, this.Pwd)
375+
err = timclient.TimLogin(context.Background(), tid, this.Pwd)
373376
if err != nil {
374377
logger.Error("cluster login err", err)
375378
this.ReConnLimit++
@@ -396,7 +399,7 @@ func (this *Connect) processor(processorchan chan int) {
396399
handler := new(TimImpl)
397400
// handler.Client = this.Super
398401
processor := NewITimProcessor(handler)
399-
protocol := thrift.NewTCompactProtocol(this.Client.Transport)
402+
protocol := thrift.NewTCompactProtocol(this.ts)
400403
for {
401404
if this == nil || this.FlowConnect == CONNECT_STOP {
402405
break
@@ -405,7 +408,7 @@ func (this *Connect) processor(processorchan chan int) {
405408
this.FlowConnect = CONNECT_RUN
406409
processorchan <- 1
407410
}
408-
b, err := processor.Process(protocol, protocol)
411+
b, err := processor.Process(context.Background(), protocol, protocol)
409412
if err != nil && !b {
410413
logger.Error("cluster processor error:", err.Error())
411414
break
Lines changed: 31 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
package client
55

66
import (
7+
"context"
78
"errors"
89
"fmt"
9-
// "time"
10-
// "runtime/debug"
10+
11+
. "tim/common"
12+
"tim/daoService"
13+
. "tim/protocol"
14+
"tim/route"
15+
"tim/utils"
1116

1217
"github.com/donnie4w/go-logger/logger"
13-
. "tim.common"
14-
"tim.daoService"
15-
. "tim.protocol"
16-
"tim.route"
17-
"tim.utils"
1818
)
1919

2020
type TimImpl struct {
@@ -25,100 +25,87 @@ type TimImpl struct {
2525

2626
// Parameters:
2727
// - Param
28-
func (this *TimImpl) TimStream(param *TimParam) (err error) {
28+
func (this *TimImpl) TimStream(ctx context.Context, param *TimParam) (err error) {
2929
panic("error")
30-
return
3130
}
32-
func (this *TimImpl) TimStarttls() (err error) {
31+
func (this *TimImpl) TimStarttls(ctx context.Context) (err error) {
3332
panic("error")
34-
return
3533
}
3634

3735
// Parameters:
3836
// - Tid
3937
// - Pwd
40-
func (this *TimImpl) TimLogin(tid *Tid, pwd string) (err error) {
38+
func (this *TimImpl) TimLogin(ctx context.Context, tid *Tid, pwd string) (err error) {
4139
logger.Debug("Login:", tid, pwd)
4240
panic("error")
43-
return
4441
}
4542

4643
// Parameters:
4744
// - Ab
48-
func (this *TimImpl) TimAck(ab *TimAckBean) (err error) {
45+
func (this *TimImpl) TimAck(ctx context.Context, ab *TimAckBean) (err error) {
4946
logger.Debug("TimAck=========>", ab)
5047
panic("error")
51-
return
5248
}
5349

5450
// Parameters:
5551
// - Pbean
56-
func (this *TimImpl) TimPresence(pbean *TimPBean) (err error) {
52+
func (this *TimImpl) TimPresence(ctx context.Context, pbean *TimPBean) (err error) {
5753
logger.Debug(pbean)
5854
panic("error")
59-
return
6055
}
6156

6257
// Parameters:
6358
// - Mbean
64-
func (this *TimImpl) TimMessage(mbean *TimMBean) (err error) {
59+
func (this *TimImpl) TimMessage(ctx context.Context, mbean *TimMBean) (err error) {
6560
logger.Debug(mbean)
6661
panic("error")
67-
return
6862
}
6963

7064
// Parameters:
7165
// - ThreadId
72-
func (this *TimImpl) TimPing(threadId string) (err error) {
66+
func (this *TimImpl) TimPing(ctx context.Context, threadId string) (err error) {
7367
panic("error")
74-
return
7568
}
7669

7770
// Parameters:
7871
// - E
79-
func (this *TimImpl) TimError(e *TimError) (err error) {
72+
func (this *TimImpl) TimError(ctx context.Context, e *TimError) (err error) {
8073
panic("error")
81-
return
8274
}
83-
func (this *TimImpl) TimLogout() (err error) {
75+
func (this *TimImpl) TimLogout(ctx context.Context) (err error) {
8476
panic("error")
85-
return
8677
}
8778

8879
// Parameters:
8980
// - Tid
9081
// - Pwd
91-
func (this *TimImpl) TimRegist(tid *Tid, pwd string) (err error) {
82+
func (this *TimImpl) TimRegist(ctx context.Context, tid *Tid, pwd string) (err error) {
9283
panic("error")
93-
return
9484
}
9585

9686
// Parameters:
9787
// - Tid
9888
// - Pwd
99-
func (this *TimImpl) TimRemoteUserAuth(tid *Tid, pwd string, auth *TimAuth) (r *TimRemoteUserBean, err error) {
89+
func (this *TimImpl) TimRemoteUserAuth(ctx context.Context, id *Tid, pwd string, auth *TimAuth) (r *TimRemoteUserBean, err error) {
10090
panic("error")
101-
return
10291
}
10392

10493
// Parameters:
10594
// - Tid
106-
func (this *TimImpl) TimRemoteUserGet(tid *Tid, auth *TimAuth) (r *TimRemoteUserBean, err error) {
95+
func (this *TimImpl) TimRemoteUserGet(ctx context.Context, tid *Tid, auth *TimAuth) (r *TimRemoteUserBean, err error) {
10796
panic("error")
108-
return
10997
}
11098

11199
// Parameters:
112100
// - Tid
113101
// - Ub
114-
func (this *TimImpl) TimRemoteUserEdit(tid *Tid, ub *TimUserBean, auth *TimAuth) (r *TimRemoteUserBean, err error) {
102+
func (this *TimImpl) TimRemoteUserEdit(ctx context.Context, tid *Tid, ub *TimUserBean, auth *TimAuth) (r *TimRemoteUserBean, err error) {
115103
panic("error")
116-
return
117104
}
118105

119106
// Parameters:
120107
// - Pbean
121-
func (this *TimImpl) TimResponsePresence(pbean *TimPBean, auth *TimAuth) (r *TimResponseBean, err error) {
108+
func (this *TimImpl) TimResponsePresence(ctx context.Context, pbean *TimPBean, auth *TimAuth) (r *TimResponseBean, err error) {
122109
logger.Debug("TimResponsePresence", pbean, auth)
123110
if !checkAuth(auth) {
124111
err = errors.New(fmt.Sprint("cluster auth fail:", auth))
@@ -144,7 +131,7 @@ func _TimResponsePresence(pbean *TimPBean, auth *TimAuth) (r *TimResponseBean, e
144131

145132
// Parameters:
146133
// - Mbean
147-
func (this *TimImpl) TimResponseMessage(mbean *TimMBean, auth *TimAuth) (r *TimResponseBean, err error) {
134+
func (this *TimImpl) TimResponseMessage(ctx context.Context, mbean *TimMBean, auth *TimAuth) (r *TimResponseBean, err error) {
148135
logger.Debug("TimResponseMessage", mbean, auth)
149136
if !checkAuth(auth) {
150137
err = errors.New(fmt.Sprint("cluster auth fail:", auth))
@@ -184,24 +171,21 @@ func _TimResponseMessage(mbean *TimMBean, auth *TimAuth) (r *TimResponseBean, er
184171
return
185172
}
186173

187-
func (this *TimImpl) TimMessageIq(timMsgIq *TimMessageIq, iqType string) (err error) {
174+
func (this *TimImpl) TimMessageIq(ctx context.Context, timMsgIq *TimMessageIq, iqType string) (err error) {
188175
logger.Debug("TimMessageIq:", timMsgIq, " ", iqType)
189176
panic("error")
190-
return
191177
}
192178

193179
// Parameters:
194180
// - Mbean
195-
func (this *TimImpl) TimMessageResult_(mbean *TimMBean) (err error) {
181+
func (this *TimImpl) TimMessageResult_(ctx context.Context, mbean *TimMBean) (err error) {
196182
logger.Debug("TimMessageResult_:", mbean)
197183
panic("error")
198-
return
199184
}
200185

201-
func (this *TimImpl) TimRoser(roster *TimRoster) (err error) {
186+
func (this *TimImpl) TimRoser(ctx context.Context, roster *TimRoster) (err error) {
202187
logger.Debug("TimRoser:", roster)
203188
panic("error")
204-
return
205189
}
206190

207191
func checkAuth(a *TimAuth) bool {
@@ -211,27 +195,24 @@ func checkAuth(a *TimAuth) bool {
211195
return false
212196
}
213197

214-
func (this *TimImpl) TimResponseMessageIq(timMsgIq *TimMessageIq, iqType string, auth *TimAuth) (r *TimMBeanList, err error) {
198+
func (this *TimImpl) TimResponseMessageIq(ctx context.Context, timMsgIq *TimMessageIq, iqType string, auth *TimAuth) (r *TimMBeanList, err error) {
215199
logger.Debug("TimResponseMessageIq:", timMsgIq, iqType, auth)
216200
panic("error TimResponseMessageIq")
217-
return
218201
}
219202

220-
func (this *TimImpl) TimMessageList(mbeanList *TimMBeanList) (err error) {
203+
func (this *TimImpl) TimMessageList(ctx context.Context, mbeanList *TimMBeanList) (err error) {
221204
logger.Debug("TimMessageList:", mbeanList)
222205
panic("error TimMessageList")
223-
return
224206
}
225207

226208
// Parameters:
227209
// - PbeanList
228-
func (this *TimImpl) TimPresenceList(pbeanList *TimPBeanList) (err error) {
210+
func (this *TimImpl) TimPresenceList(ctx context.Context, pbeanList *TimPBeanList) (err error) {
229211
logger.Debug("TimPresenceList:", pbeanList)
230212
panic("error TimPresenceList")
231-
return
232213
}
233214

234-
func (this *TimImpl) TimResponsePresenceList(pbeanList *TimPBeanList, auth *TimAuth) (r *TimResponseBean, err error) {
215+
func (this *TimImpl) TimResponsePresenceList(ctx context.Context, pbeanList *TimPBeanList, auth *TimAuth) (r *TimResponseBean, err error) {
235216
if !checkAuth(auth) {
236217
err = errors.New(fmt.Sprint("cluster TimResponsePresenceList fail:", auth))
237218
return
@@ -266,7 +247,7 @@ func _TimResponsePresenceList(pbeanList *TimPBeanList, auth *TimAuth) (r *TimRes
266247
// Parameters:
267248
// - MbeanList
268249
// - Auth
269-
func (this *TimImpl) TimResponseMessageList(mbeanList *TimMBeanList, auth *TimAuth) (r *TimResponseBean, err error) {
250+
func (this *TimImpl) TimResponseMessageList(ctx context.Context, mbeanList *TimMBeanList, auth *TimAuth) (r *TimResponseBean, err error) {
270251
if !checkAuth(auth) {
271252
err = errors.New(fmt.Sprint("cluster TimResponseMessageList fail:", auth))
272253
return
@@ -298,7 +279,7 @@ func _TimResponseMessageList(mbeanList *TimMBeanList, auth *TimAuth) (r *TimResp
298279
return
299280
}
300281

301-
func (this *TimImpl) TimProperty(tpb *TimPropertyBean) (err error) {
282+
func (this *TimImpl) TimProperty(ctx context.Context, tpb *TimPropertyBean) (err error) {
302283
logger.Debug("TimProperty:", tpb)
303284
return
304285
}

0 commit comments

Comments
 (0)