public synchronized Map<String, Object> getConnectionInfo(boolean brief) { Map<String, Object> info = new LinkedHashMap<String, Object>(); info.put("remote_socket_address", getRemoteSocketAddress()); info.put("interest_ops", getInterestOps()); info.put("outstanding_requests", getOutstandingRequests()); info.put("packets_received", getPacketsReceived()); info.put("packets_sent", getPacketsSent()); if (!brief) { info.put("session_id", getSessionId()); info.put("last_operation", getLastOperation()); info.put("established", getEstablished()); info.put("session_timeout", getSessionTimeout()); info.put("last_cxid", getLastCxid()); info.put("last_zxid", getLastZxid()); info.put("last_response_time", getLastResponseTime()); info.put("last_latency", getLastLatency()); info.put("min_latency", getMinLatency()); info.put("avg_latency", getAvgLatency()); info.put("max_latency", getMaxLatency()); } return info; }
public void terminateConnection() { connection.sendCloseSession(); }
byte[] authData) { X509Certificate[] certChain = (X509Certificate[]) cnxn.getClientCertificateChain(); Long.toHexString(cnxn.getSessionId())); return KeeperException.Code.AUTHFAILED; } catch (CertificateException ce) { LOG.error("Failed to trust certificate for session 0x" + Long.toHexString(cnxn.getSessionId()), ce); return KeeperException.Code.AUTHFAILED; cnxn.addAuthInfo(new Id("super", clientId)); LOG.info("Authenticated Id '{}' as super user", clientId); cnxn.addAuthInfo(authInfo);
/** * clear all the connections in the selector * */ @Override @SuppressWarnings("unchecked") public void closeAll() { // clear all the connections on which we are selecting for (ServerCnxn cnxn : cnxns) { try { // This will remove the cnxn from cnxns cnxn.close(); } catch (Exception e) { LOG.warn("Ignoring exception closing cnxn sessionid 0x" + Long.toHexString(cnxn.getSessionId()), e); } } }
public ConnectionBean(ServerCnxn connection,ZooKeeperServer zk){ this.connection = connection; this.stats = connection; this.zk = zk; InetSocketAddress sockAddr = connection.getRemoteSocketAddress(); if (sockAddr == null) { remoteIP = "Unknown"; } else { InetAddress addr = sockAddr.getAddress(); if (addr instanceof Inet6Address) { remoteIP = ObjectName.quote(addr.getHostAddress()); } else { remoteIP = addr.getHostAddress(); } } sessionId = connection.getSessionId(); }
ConnectResponse rsp = new ConnectResponse(0, valid ? cnxn.getSessionTimeout() : 0, valid ? cnxn.getSessionId() : 0, // send 0 if session is no valid ? generatePasswd(cnxn.getSessionId()) : new byte[16]); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); bb.putInt(bb.remaining() - 4).rewind(); cnxn.sendBuffer(bb); + Long.toHexString(cnxn.getSessionId()) + " with negotiated timeout " + cnxn.getSessionTimeout() + " for client " + cnxn.getRemoteSocketAddress()); cnxn.enableRecv(); } else { + Long.toHexString(cnxn.getSessionId()) + " for client " + cnxn.getRemoteSocketAddress() + ", probably expired"); cnxn.sendBuffer(ServerCnxnFactory.closeConn); cnxn.close();
cnxn.incrOutstandingAndCheckThrottle(h); LOG.info("got auth packet " + cnxn.getRemoteSocketAddress()); AuthPacket authPacket = new AuthPacket(); ByteBufferInputStream.byteBuffer2Record(incomingBuffer, authPacket); LOG.debug("Authentication succeeded for scheme: " + scheme); LOG.info("auth success " + cnxn.getRemoteSocketAddress()); ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue()); cnxn.sendResponse(rh, null, null); } else { if (ap == null) { cnxn.sendResponse(rh, null, null); cnxn.sendBuffer(ServerCnxnFactory.closeConn); cnxn.disableRecv(); Record rsp = processSasl(incomingBuffer,cnxn); ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue()); cnxn.sendResponse(rh,rsp, "response"); // not sure about 3rd arg..what is it? return; } else { Request si = new Request(cnxn, cnxn.getSessionId(), h.getXid(), h.getType(), incomingBuffer, cnxn.getAuthInfo()); si.setOwner(ServerCnxn.me);
LOG.info("got auth packet " + cnxn.getRemoteSocketAddress()); AuthPacket authPacket = new AuthPacket(); ByteBufferInputStream.byteBuffer2Record(incomingBuffer, authPacket); cnxn.sendResponse(rh, null, null); cnxn.sendBuffer(ServerCnxnFactory.closeConn); cnxn.disableRecv(); } else { if (LOG.isDebugEnabled()) { LOG.info("auth success " + cnxn.getRemoteSocketAddress()); ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue()); cnxn.sendResponse(rh, null, null); Record rsp = processSasl(incomingBuffer,cnxn); ReplyHeader rh = new ReplyHeader(h.getXid(), 0, KeeperException.Code.OK.intValue()); cnxn.sendResponse(rh,rsp, "response"); // not sure about 3rd arg..what is it? return; Request si = new Request(cnxn, cnxn.getSessionId(), h.getXid(), h.getType(), incomingBuffer, cnxn.getAuthInfo()); si.setOwner(ServerCnxn.me); submitRequest(si); cnxn.incrOutstandingRequests(h);
public void removeCnxnFromSessionMap(ServerCnxn cnxn) { long sessionId = cnxn.getSessionId(); if (sessionId != 0) { sessionMap.remove(sessionId); } }
if (LOG.isDebugEnabled()) { LOG.debug("Session establishment request from client " + cnxn.getRemoteSocketAddress() + " client's lastZxid is 0x" + Long.toHexString(connReq.getLastZxidSeen())); + cnxn.getRemoteSocketAddress() + "; will be dropped if server is in r-o mode"); + cnxn.getRemoteSocketAddress(); LOG.info(msg); throw new CloseRequestException(msg); + cnxn.getRemoteSocketAddress() + " as it has seen zxid 0x" + Long.toHexString(connReq.getLastZxidSeen()) cnxn.setSessionTimeout(sessionTimeout); cnxn.disableRecv(); long sessionId = connReq.getSessionId(); if (sessionId == 0) { Long.toHexString(connReq.getLastZxidSeen()), connReq.getTimeOut(), cnxn.getRemoteSocketAddress()); } else { long clientSessionId = connReq.getSessionId();
public void processRequest(Request request) throws RequestProcessorException { KeeperException ke = new KeeperException.UnimplementedException(); request.setException(ke); ReplyHeader rh = new ReplyHeader(request.cxid, request.zxid, ke.code().intValue()); try { request.cnxn.sendResponse(rh, null, "response"); } catch (IOException e) { throw new RequestProcessorException("Can't send the response", e); } request.cnxn.sendCloseSession(); }
void touch(ServerCnxn cnxn) throws MissingSessionException { if (cnxn == null) { return; } long id = cnxn.getSessionId(); int to = cnxn.getSessionTimeout(); if (!sessionTracker.touchSession(id, to)) { throw new MissingSessionException( "No session with sessionid 0x" + Long.toHexString(id) + " exists, probably expired and removed"); } }
cnxn.updateStatsForResponse(request.cxid, request.zxid, lastOp, request.createTime, Time.currentElapsedTime()); cnxn.sendResponse(new ReplyHeader(-2, zks.getZKDatabase().getDataTreeLastProcessedZxid(), 0), null, "response"); return; cnxn.updateStatsForResponse(request.cxid, request.zxid, lastOp, request.createTime, Time.currentElapsedTime()); cnxn.sendCloseSession(); return; } catch (KeeperException e) { cnxn.updateStatsForResponse(request.cxid, lastZxid, lastOp, request.createTime, Time.currentElapsedTime()); cnxn.sendResponse(hdr, rsp, "response"); if (closeSession) { cnxn.sendCloseSession();
((CnxnStats)cnxn.getStats()) .updateForResponse(request.cxid, request.zxid, lastOp, request.createTime, System.currentTimeMillis()); cnxn.sendResponse(new ReplyHeader(-2, zks.getZKDatabase().getDataTreeLastProcessedZxid(), 0), null, "response"); return; ((CnxnStats)cnxn.getStats()) .updateForResponse(request.cxid, request.zxid, lastOp, request.createTime, System.currentTimeMillis()); cnxn.finishSessionInit(true); return; cnxn.sendCloseSession(); return; } catch (KeeperException e) { ((CnxnStats)cnxn.getStats()) .updateForResponse(request.cxid, request.zxid, lastOp, request.createTime, System.currentTimeMillis()); cnxn.sendResponse(hdr, rsp, "response"); if (closeSession) { cnxn.sendCloseSession();
String authorizationID = saslServer.getAuthorizationID(); LOG.info("adding SASL authorization for authorizationID: " + authorizationID); cnxn.addAuthInfo(new Id("sasl",authorizationID)); if (System.getProperty("zookeeper.superUser") != null && authorizationID.equals(System.getProperty("zookeeper.superUser"))) { cnxn.addAuthInfo(new Id("super", "")); } else { LOG.warn("Closing client connection due to SASL authentication failure."); cnxn.close();
public KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) { String id = cnxn.getRemoteSocketAddress().getAddress().getHostAddress(); cnxn.addAuthInfo(new Id(getScheme(), id)); return KeeperException.Code.OK; }
public void removeCnxn(ServerCnxn cnxn) { synchronized(cnxns){ // if this is not in cnxns then it's already closed if (!cnxns.remove(cnxn)) { if (LOG.isDebugEnabled()) { LOG.debug("cnxns size:" + cnxns.size()); } return; } if (LOG.isDebugEnabled()) { LOG.debug("close in progress for sessionid:0x" + Long.toHexString(cnxn.getSessionId())); } synchronized (ipMap) { Set<NettyServerCnxn> s = ipMap.get(cnxn.getSocketAddress()); s.remove(cnxn); } } }
public ConnectionBean(ServerCnxn connection,ZooKeeperServer zk){ this.connection = connection; this.stats = (CnxnStats)connection.getStats(); this.zk = zk; InetSocketAddress sockAddr = connection.getRemoteAddress(); if (sockAddr == null) { remoteIP = "Unknown"; } else { InetAddress addr = sockAddr.getAddress(); if (addr instanceof Inet6Address) { remoteIP = ObjectName.quote(addr.getHostAddress()); } else { remoteIP = addr.getHostAddress(); } } sessionId = connection.getSessionId(); }
public KeeperException.Code handleAuthentication(ServerCnxn cnxn, byte[] authData) { String id = new String(authData); try { String digest = generateDigest(id); if (digest.equals(superDigest)) { cnxn.addAuthInfo(new Id("super", "")); } cnxn.addAuthInfo(new Id(getScheme(), digest)); return KeeperException.Code.OK; } catch (NoSuchAlgorithmException e) { LOG.error("Missing algorithm",e); } return KeeperException.Code.AUTHFAILED; }
public void sendResponse(ReplyHeader h, Record r, String tag) throws IOException { sendResponse(h, r, tag, null, null); }