Search in sources :

Example 6 with CmppConnectRequestMessage

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

the class SessionLoginManager method failedLogin.

@Override
protected /**
 * 状态 0:正确 1:消息结构错 2:非法源地址 3:认证错 4:版本太高 5~ :其他错误
 */
void failedLogin(ChannelHandlerContext ctx, Object msg, long status) {
    if (msg instanceof CmppConnectRequestMessage) {
        logger.error("Connected error status :{},msg : {}", status, msg);
        CmppConnectRequestMessage message = (CmppConnectRequestMessage) msg;
        // 认证失败
        CmppConnectResponseMessage resp = new CmppConnectResponseMessage(message.getHeader().getSequenceId());
        resp.setAuthenticatorISMG(new byte[16]);
        resp.setStatus(status);
        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) CmppConnectRequestMessage(com.zx.sms.codec.cmpp.msg.CmppConnectRequestMessage) CmppConnectResponseMessage(com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener)

Example 7 with CmppConnectRequestMessage

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

the class SessionLoginManager method doLogin.

@Override
protected void doLogin(Channel ch) {
    CMPPEndpointEntity cliententity = (CMPPEndpointEntity) entity;
    CmppConnectRequestMessage req = new CmppConnectRequestMessage();
    req.setSourceAddr(cliententity.getUserName());
    String timestamp = DateFormatUtils.format(CachedMillisecondClock.INS.now(), "MMddHHmmss");
    req.setTimestamp(Long.parseLong(timestamp));
    byte[] userBytes = cliententity.getUserName().getBytes(cliententity.getChartset());
    byte[] passwdBytes = cliententity.getPassword().getBytes(cliententity.getChartset());
    byte[] timestampBytes = timestamp.getBytes(cliententity.getChartset());
    req.setAuthenticatorSource(DigestUtils.md5(Bytes.concat(userBytes, new byte[9], passwdBytes, timestampBytes)));
    req.setVersion(cliententity.getVersion());
    ch.writeAndFlush(req);
    logger.info("session Start :Send CmppConnectRequestMessage seq :{}", req.getHeader().getSequenceId());
}
Also used : CMPPEndpointEntity(com.zx.sms.connect.manager.cmpp.CMPPEndpointEntity) 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