Skip to content

Commit

Permalink
Merge branch 'v1-feature-main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
dobyte committed Dec 1, 2022
2 parents 370b4f4 + f43e6ab commit 6eff2a2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions cluster/node/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (p *provider) Trigger(event cluster.Event, gid string, uid int64) {
// Deliver 投递消息
func (p *provider) Deliver(gid, nid string, cid, uid int64, message *transport.Message) {
p.node.deliverRequest(&request{
ctx: context.Background(),
gid: gid,
nid: nid,
cid: cid,
Expand Down
1 change: 1 addition & 0 deletions cluster/node/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ func (p *proxy) Deliver(ctx context.Context, args *DeliverArgs) error {
switch {
case args.NID == p.node.opts.id:
p.node.deliverRequest(&request{
ctx: context.Background(),
nid: p.node.opts.id,
uid: args.UID,
node: p.node,
Expand Down
40 changes: 31 additions & 9 deletions cluster/node/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,21 @@ type Request interface {
BindNode() error
// UnbindNode 解绑节点
UnbindNode() error
// Disconnect 断开连接
Disconnect(isForce ...bool) error
}

// 请求数据
type request struct {
gid string // 来源网关ID
nid string // 来源节点ID
cid int64 // 连接ID
uid int64 // 用户ID
seq int32 // 消息序列号
route int32 // 消息路由
data interface{} // 消息内容
node *Node // 节点服务器
ctx context.Context // context
gid string // 来源网关ID
nid string // 来源节点ID
cid int64 // 连接ID
uid int64 // 用户ID
seq int32 // 消息序列号
route int32 // 消息路由
data interface{} // 消息内容
node *Node // 节点服务器
}

// GID 获取来源网关ID
Expand Down Expand Up @@ -117,7 +120,7 @@ func (r *request) Parse(v interface{}) (err error) {

// Context 获取上线文
func (r *request) Context() context.Context {
return context.Background()
return r.ctx
}

// GetIP 获取IP地址
Expand Down Expand Up @@ -153,3 +156,22 @@ func (r *request) BindNode() error {
func (r *request) UnbindNode() error {
return r.node.proxy.UnbindNode(r.Context(), r.uid)
}

// Disconnect 断开连接
func (r *request) Disconnect(isForce ...bool) error {
if r.gid == "" {
return nil
}

isForceClose := false
if len(isForce) > 0 && isForce[0] {
isForceClose = true
}

return r.node.proxy.Disconnect(r.Context(), &DisconnectArgs{
GID: r.gid,
Kind: session.Conn,
Target: r.cid,
IsForce: isForceClose,
})
}
3 changes: 0 additions & 3 deletions cluster/node/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,3 @@ type DeliverArgs struct {
UID int64 // 用户ID
Message *Message // 消息
}

type deliverArgs struct {
}

0 comments on commit 6eff2a2

Please sign in to comment.