Search in sources :

Example 1 with SgipBindRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.

the class SgipBindRequestMessageCodec method decode.

@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
    int commandId = msg.getHeader().getCommandId();
    if (packetType.getCommandId() != commandId) {
        // 不解析,交给下一个codec
        out.add(msg);
        return;
    }
    SgipBindRequestMessage requestMessage = new SgipBindRequestMessage(msg.getHeader());
    requestMessage.setTimestamp(msg.getTimestamp());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setLoginType(bodyBuffer.readUnsignedByte());
    requestMessage.setLoginName(bodyBuffer.readCharSequence(SgipBindRequest.LOGINNAME.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setLoginPassowrd(bodyBuffer.readCharSequence(SgipBindRequest.LOGINPASSWD.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setReserve(bodyBuffer.readCharSequence(SgipBindRequest.RESERVE.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(requestMessage);
}
Also used : SgipBindRequestMessage(com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 2 with SgipBindRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.

the class SgipSessionLoginManager method doLogin.

@Override
protected void doLogin(Channel ch) {
    // 发送bind请求
    SgipEndpointEntity sgipentity = (SgipEndpointEntity) entity;
    SgipBindRequestMessage bind = createBindRequest(sgipentity);
    ch.writeAndFlush(bind);
}
Also used : SgipBindRequestMessage(com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage) SgipEndpointEntity(com.zx.sms.connect.manager.sgip.SgipEndpointEntity)

Example 3 with SgipBindRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.

the class SgipSessionLoginManager method validClientMsg.

@Override
protected int validClientMsg(EndpointEntity entity, Object msg) {
    SgipEndpointEntity sgipentity = (SgipEndpointEntity) entity;
    SgipBindRequestMessage message = (SgipBindRequestMessage) msg;
    if (sgipentity.getLoginName().equals(message.getLoginName()) && sgipentity.getLoginPassowrd().equals(message.getLoginPassowrd())) {
        return 0;
    } else {
        return 1;
    }
}
Also used : SgipBindRequestMessage(com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage) SgipEndpointEntity(com.zx.sms.connect.manager.sgip.SgipEndpointEntity)

Example 4 with SgipBindRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.

the class SgipSessionLoginManager method failedLogin.

@Override
protected void failedLogin(ChannelHandlerContext ctx, Object msg, long status) {
    if (msg instanceof SgipBindRequestMessage) {
        logger.error("Connected error status :{},msg : {}", status, msg);
        SgipBindRequestMessage message = (SgipBindRequestMessage) msg;
        // 认证失败
        SgipBindResponseMessage resp = new SgipBindResponseMessage(((Message) message).getHeader());
        resp.setResult((short) status);
        resp.setTimestamp(((Message) message).getTimestamp());
        ChannelFuture promise = ctx.writeAndFlush(resp);
        final ChannelHandlerContext finalctx = ctx;
        promise.addListener(new GenericFutureListener() {

            public void operationComplete(Future future) throws Exception {
                finalctx.close();
            }
        });
    } else {
        logger.error("connect msg type error : {}", msg);
        ctx.close();
    }
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) ChannelFuture(io.netty.channel.ChannelFuture) Future(io.netty.util.concurrent.Future) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) SgipBindResponseMessage(com.zx.sms.codec.sgip12.msg.SgipBindResponseMessage) SgipBindRequestMessage(com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Example 5 with SgipBindRequestMessage

use of com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage in project SMSGate by Lihuanghe.

the class SgipSessionLoginManager method createBindRequest.

private SgipBindRequestMessage createBindRequest(SgipEndpointEntity entity) {
    SgipBindRequestMessage req = new SgipBindRequestMessage();
    req.setLoginName(entity.getLoginName());
    req.setLoginPassowrd(entity.getLoginPassowrd());
    req.getHeader().setNodeId(entity.getNodeId());
    /**
     * 登录类型。
     * 1:SP向SMG建立的连接,用于发送命令
     * 2:SMG向SP建立的连接,用于发送命令
     * 3:SMG之间建立的连接,用于转发命令
     * 4:SMG向GNS建立的连接,用于路由表的检索和维护
     * 5:GNS向SMG建立的连接,用于路由表的更新
     * 6:主备GNS之间建立的连接,用于主备路由表的一致性
     * 11:SP与SMG以及SMG之间建立的测试连接,用于跟踪测试
     * 其它:保留
     */
    if (entity.getChannelType() == ChannelType.UP) {
        req.setLoginType((short) 2);
    } else if (entity.getChannelType() == ChannelType.DOWN) {
        req.setLoginType((short) 1);
    }
    return req;
}
Also used : SgipBindRequestMessage(com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage)

Aggregations

SgipBindRequestMessage (com.zx.sms.codec.sgip12.msg.SgipBindRequestMessage)6 SgipEndpointEntity (com.zx.sms.connect.manager.sgip.SgipEndpointEntity)2 SgipBindResponseMessage (com.zx.sms.codec.sgip12.msg.SgipBindResponseMessage)1 SgipServerEndpointEntity (com.zx.sms.connect.manager.sgip.SgipServerEndpointEntity)1 ByteBuf (io.netty.buffer.ByteBuf)1 ChannelFuture (io.netty.channel.ChannelFuture)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 Future (io.netty.util.concurrent.Future)1 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)1