private boolean addInternal(RemoteFileDesc host) { // initialize the sha1 if we don't have one if (sha1 == null) { if (host.getSHA1Urn() != null) sha1 = host.getSHA1Urn(); else // BUGFIX: We can't discard sources w/out a SHA1 when we dont' have // a SHA1 for the download, or else it won't be possible to download a // file from a query hit without a SHA1, if we can received UDP pings return testedLocations.add(host); // we can't do anything yet } // do not allow duplicate hosts if (running && knowsAboutHost(host)) return false; if (LOG.isDebugEnabled()) LOG.debug("adding new host " + host + " " + host.getPushAddr()); boolean ret = false; // don't bother ranking multicasts if (host.isReplyToMulticast()) ret = verifiedHosts.add(host); else ret = newHosts.add(host); // rank // make sure that if we were stopped, we return true ret = ret | !running; // initialize the guid if we don't have one if (myGUID == null && meshHandler != null) { myGUID = new GUID(GUID.makeGuid()); RouterService.getMessageRouter().registerMessageListener(myGUID.bytes(), this); } return ret; }
public void writeMessageHeaders(OutputStream ostream) throws IOException { LOG.debug("writing headers"); byte[] clientGUID = GUID.fromHexString(UPLOADER.getFileName()); InetAddress hostAddress = UPLOADER.getNodeAddress(); int hostPort = UPLOADER.getNodePort(); if (clientGUID.length != 16 || hostAddress == null || !NetworkUtils.isValidPort(hostPort) || !NetworkUtils.isValidAddress(hostAddress)) { // send back a 400 String str = "HTTP/1.1 400 Push Proxy: Bad Request\r\n\r\n"; ostream.write(str.getBytes()); ostream.flush(); debug("PPUS.doUpload(): unknown host."); UploadStat.PUSH_PROXY_REQ_BAD.incrementStat(); return; } Map params = UPLOADER.getParameters(); int fileIndex = 0; // default to 0. Object index = params.get(P_FILE); // set the file index if we know it... if (index != null) fileIndex = ((Integer) index).intValue(); PushRequest push = new PushRequest( GUID.makeGuid(), (byte) 0, clientGUID, fileIndex, hostAddress.getAddress(), hostPort); try { RouterService.getMessageRouter().sendPushRequest(push); } catch (IOException ioe) { // send back a 410 String str = "HTTP/1.1 410 Push Proxy: Servent not connected\r\n\r\n"; ostream.write(str.getBytes()); ostream.flush(); debug("PPUS.doUpload(): push failed."); debug(ioe); UploadStat.PUSH_PROXY_REQ_FAILED.incrementStat(); return; } UploadStat.PUSH_PROXY_REQ_SUCCESS.incrementStat(); String str; str = "HTTP/1.1 202 Push Proxy: Message Sent\r\n"; ostream.write(str.getBytes()); str = "Server: " + CommonUtils.getHttpServer() + "\r\n"; ostream.write(str.getBytes()); str = "Content-Type: " + Constants.QUERYREPLY_MIME_TYPE + "\r\n"; ostream.write(str.getBytes()); str = "Content-Length: " + BAOS.size() + "\r\n"; ostream.write(str.getBytes()); str = "\r\n"; ostream.write(str.getBytes()); }