Search in sources :

Example 1 with CmppConnectRequestMessage

use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.

the class SessionLoginManager method doLoginSuccess.

@Override
protected void doLoginSuccess(ChannelHandlerContext ctx, EndpointEntity entity, Object msg) {
    CMPPServerChildEndpointEntity childentity = (CMPPServerChildEndpointEntity) entity;
    CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
    // channelHandler已绑定完成,给客户端发resp.
    CmppConnectResponseMessage resp = new CmppConnectResponseMessage(message.getHeader().getSequenceId());
    resp.setVersion(childentity.getVersion());
    resp.setStatus(0);
    resp.setAuthenticatorISMG(DigestUtils.md5(Bytes.concat(Ints.toByteArray((int) resp.getStatus()), message.getAuthenticatorSource(), childentity.getPassword().getBytes(childentity.getChartset()))));
    ctx.channel().writeAndFlush(resp);
}
Also used : CMPPServerChildEndpointEntity(com.zx.sms.connect.manager.cmpp.CMPPServerChildEndpointEntity) CmppConnectRequestMessage(com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage) CmppConnectResponseMessage(com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage)

Example 2 with CmppConnectRequestMessage

use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.

the class CmppConnectRequestMessageCodec 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;
    }
    CmppConnectRequestMessage requestMessage = new CmppConnectRequestMessage(msg.getHeader());
    ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
    requestMessage.setSourceAddr(bodyBuffer.readCharSequence(CmppConnectRequest.SOURCEADDR.getLength(), GlobalConstance.defaultTransportCharset).toString().trim());
    requestMessage.setAuthenticatorSource(toArray(bodyBuffer, CmppConnectRequest.AUTHENTICATORSOURCE.getLength()));
    requestMessage.setVersion(bodyBuffer.readUnsignedByte());
    requestMessage.setTimestamp(bodyBuffer.readUnsignedInt());
    ReferenceCountUtil.release(bodyBuffer);
    out.add(requestMessage);
}
Also used : CmppConnectRequestMessage(com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage) ByteBuf(io.netty.buffer.ByteBuf)

Example 3 with CmppConnectRequestMessage

use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.

the class TestCmppConnectRequestMessageCodec method testCode.

@Test
public void testCode() {
    CmppConnectRequestMessage msg = new CmppConnectRequestMessage();
    msg.setSourceAddr("106581");
    // 长度为16
    msg.setAuthenticatorSource("passwordpassword".getBytes());
    ByteBuf buf = encode(msg);
    ByteBuf copybuf = buf.copy();
    int length = buf.readableBytes();
    int expectLength = CmppConnectRequest.AUTHENTICATORSOURCE.getBodyLength() + CmppHead.COMMANDID.getHeadLength();
    Assert.assertEquals(expectLength, length);
    Assert.assertEquals(expectLength, buf.readInt());
    Assert.assertEquals(msg.getPacketType().getCommandId(), buf.readInt());
    Assert.assertEquals(msg.getHeader().getSequenceId(), buf.readInt());
    CmppConnectRequestMessage result = decode(copybuf);
    Assert.assertEquals(msg.getHeader().getSequenceId(), result.getHeader().getSequenceId());
    Assert.assertEquals(msg.getSourceAddr(), result.getSourceAddr());
    Assert.assertArrayEquals(msg.getAuthenticatorSource(), result.getAuthenticatorSource());
}
Also used : CmppConnectRequestMessage(com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage) ByteBuf(io.netty.buffer.ByteBuf) Test(org.junit.Test)

Example 4 with CmppConnectRequestMessage

use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.

the class SessionLoginManager method queryEndpointEntityByMsg.

@Override
protected EndpointEntity queryEndpointEntityByMsg(Object msg) {
    if (msg instanceof CmppConnectRequestMessage) {
        CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
        String username = message.getSourceAddr();
        if (entity instanceof ServerEndpoint) {
            ServerEndpoint serverEntity = (ServerEndpoint) entity;
            return serverEntity.getChild(username.trim());
        }
    }
    return null;
}
Also used : CmppConnectRequestMessage(com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage) ServerEndpoint(com.zx.sms.connect.manager.ServerEndpoint)

Example 5 with CmppConnectRequestMessage

use of com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage in project SMSGate by Lihuanghe.

the class SessionLoginManager method changeProtoVersion.

@Override
protected void changeProtoVersion(ChannelHandlerContext ctx, EndpointEntity entity, Object msg) throws Exception {
    CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
    final short clientVersion = message.getVersion();
    short aim_ver = clientVersion;
    if (entity != null) {
        CMPPServerChildEndpointEntity childentity = (CMPPServerChildEndpointEntity) entity;
        // 以服务端配置的版本为准
        aim_ver = childentity.getVersion();
        // 发送ConnectRequest里的Version跟配置的不同
        if (aim_ver != clientVersion) {
            logger.warn("receive version code {} ,expected version is {} .I would use version {}", clientVersion, aim_ver, aim_ver);
        }
    }
    if ((short) 0x30 != aim_ver) {
        // 以配置的协议版本为准
        // 更换协议解析器
        logger.info("changeCodec to version:{}", aim_ver);
        ctx.pipeline().replace(GlobalConstance.codecName, GlobalConstance.codecName, CMPPCodecChannelInitializer.getCodecHandler(aim_ver));
    }
}
Also used : CMPPServerChildEndpointEntity(com.zx.sms.connect.manager.cmpp.CMPPServerChildEndpointEntity) CmppConnectRequestMessage(com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage)

Aggregations

CmppConnectRequestMessage (com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage)7 CmppConnectResponseMessage (com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage)2 CMPPServerChildEndpointEntity (com.zx.sms.connect.manager.cmpp.CMPPServerChildEndpointEntity)2 ByteBuf (io.netty.buffer.ByteBuf)2 ServerEndpoint (com.zx.sms.connect.manager.ServerEndpoint)1 CMPPEndpointEntity (com.zx.sms.connect.manager.cmpp.CMPPEndpointEntity)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 Test (org.junit.Test)1