⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 automaticconfigurator.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        XMLDocument httAdvDoc = (XMLDocument) httpAdv.getDocument(MimeMediaType.XMLUTF8);        StructuredDocumentUtils.copyElements(http, http, httAdvDoc);        if (!httpEnabled) {            http.appendChild(http.createElement("isOff"));        }        advertisement.putServiceParam(PeerGroup.httpProtoClassID, http);        // Check the TCP Message Transport parameters.        XMLDocument tcp = (XMLDocument) advertisement.getServiceParam(PeerGroup.tcpProtoClassID);        TCPAdv tcpAdv = null;        boolean tcpEnabled = true;        if (tcp != null) {            try {                tcpEnabled = advertisement.isSvcEnabled(PeerGroup.tcpProtoClassID);                XMLElement param = null;                Enumeration tcpChilds = tcp.getChildren(TransportAdvertisement.getAdvertisementType());                // get the TransportAdv                if (tcpChilds.hasMoreElements()) {                    param = (XMLElement) tcpChilds.nextElement();                }                if (null != param) {                    tcpAdv = (TCPAdv) AdvertisementFactory.newAdvertisement(param);                    if (tcpEnabled) {                        String intf = tcpAdv.getInterfaceAddress();                        if ((null != intf) && !isValidInetAddress(intf)) {                            reconf = true;                            if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) {                                LOG.config("Reconfig requested - invalid interface address");                            }                        }                    }                }            } catch (RuntimeException advTrouble) {                if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                    LOG.log(Level.WARNING, "TCP advertisement corrupted", advTrouble);                }                tcpAdv = null;            }        }        if (tcpAdv == null) {            if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) {                LOG.config("TCP advertisement missing, making a new one.");            }            int port = 0;            // get the port from a property            String tcpPort = System.getProperty("jxta.tcp.port");            if (tcpPort != null) {                try {                    int propertyPort = Integer.parseInt(tcpPort);                    if ((propertyPort < 65536) && (propertyPort >= 0)) {                        port = propertyPort;                    } else {                        if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                            LOG.warning("Property \'jxta.tcp.port\' is not a valid port number : " + propertyPort);                        }                    }                } catch (NumberFormatException ignored) {                    if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                        LOG.warning("Property \'jxta.tcp.port\' was not an integer : " + tcpPort);                    }                }            }            tcpAdv = (TCPAdv) AdvertisementFactory.newAdvertisement(TCPAdv.getAdvertisementType());            tcpAdv.setProtocol("tcp");            tcpAdv.setPort(port);            tcpAdv.setMulticastAddr("224.0.1.85");            tcpAdv.setMulticastPort(1234);            tcpAdv.setMulticastSize(16384);            tcpAdv.setMulticastState(true);        }        tcp = (XMLDocument) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Parm");        StructuredDocumentUtils.copyElements(tcp, tcp, (XMLDocument) tcpAdv.getDocument(MimeMediaType.XMLUTF8));        if (!tcpEnabled) {            tcp.appendChild(tcp.createElement("isOff"));        }        advertisement.putServiceParam(PeerGroup.tcpProtoClassID, tcp);        // Check the relay config        RelayConfigAdv relayConfig = null;        try {            XMLElement param = (XMLElement) advertisement.getServiceParam(PeerGroup.relayProtoClassID);            if (param != null) {                // XXX 20041027 backwards compatibility                param.addAttribute("type", RelayConfigAdv.getAdvertisementType());                relayConfig = (RelayConfigAdv) AdvertisementFactory.newAdvertisement(param);            }        } catch (Exception failure) {            if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                LOG.log(Level.WARNING, "Problem reading relay configuration", failure);            }        }        if (null == relayConfig) {            if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) {                LOG.config("Relay Config advertisement missing, making a new one.");            }            // restore default values.            relayConfig = (RelayConfigAdv) AdvertisementFactory.newAdvertisement(RelayConfigAdv.getAdvertisementType());            // Enable relay if any transport doesn't support incoming.            if (!tcpAdv.isServerEnabled() || !httpAdv.isServerEnabled()) {                relayConfig.setClientEnabled(true);            }        }        /*         if( (0 == relayConfig.getSeedingURIs().length) && (0 == relayConfig.getSeedRelays().length) && !relayConfig.isServerEnabled() ) {         // add the default relay seeding peer.         relayConfig.addSeedingURI( "http://rdv.jxtahosts.net/cgi-bin/relays.cgi?3" );         }         */        XMLDocument relayDoc = (XMLDocument) relayConfig.getDocument(MimeMediaType.XMLUTF8);        advertisement.putServiceParam(PeerGroup.relayProtoClassID, relayDoc);        // Check Rendezvous Configuration        RdvConfigAdv rdvAdv = null;        try {            XMLElement param = (XMLElement) advertisement.getServiceParam(PeerGroup.rendezvousClassID);            if (param != null) {                // XXX 20041027 backwards compatibility                param.addAttribute("type", RdvConfigAdv.getAdvertisementType());                rdvAdv = (RdvConfigAdv) AdvertisementFactory.newAdvertisement(param);            }        } catch (Exception failure) {            if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                LOG.log(Level.WARNING, "Problem reading rendezvous configuration", failure);            }        }        if (null == rdvAdv) {            if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) {                LOG.config("Rdv Config advertisement missing, making a new one.");            }            // restore default values.            rdvAdv = (RdvConfigAdv) AdvertisementFactory.newAdvertisement(RdvConfigAdv.getAdvertisementType());        }        /*         if( (0 == rdvAdv.getSeedingURIs().length) &&         (0 == rdvAdv.getSeedRendezvous().length) &&         (RdvConfigAdv.RendezVousConfiguration.RENDEZVOUS != rdvAdv.getConfiguration()) &&         (RdvConfigAdv.RendezVousConfiguration.AD_HOC != rdvAdv.getConfiguration()) &&         !relayConfig.isClientEnabled() ) {         // add the default rendezvous seeding peer if we don't know of any rendezvous, aren't a rendezvous ourselves, aren't in ad-hoc mode or using a relay.         rdvAdv.addSeedingURI( "http://rdv.jxtahosts.net/cgi-bin/rendezvous.cgi?3" );         }         */        XMLDocument rdvDoc = (XMLDocument) rdvAdv.getDocument(MimeMediaType.XMLUTF8);        advertisement.putServiceParam(PeerGroup.rendezvousClassID, rdvDoc);        // if no proxy param section, disable it.        XMLDocument proxy = (XMLDocument) advertisement.getServiceParam(PeerGroup.proxyClassID);        if (null == proxy) {            if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) {                LOG.config("Proxy config advertisement missing, making a new one.");            }            proxy = (XMLDocument) StructuredDocumentFactory.newStructuredDocument(MimeMediaType.XMLUTF8, "Parm");            proxy.appendChild(proxy.createElement("isOff"));            advertisement.putServiceParam(PeerGroup.proxyClassID, proxy);        }        // Check the PSE Configuration        PSEConfigAdv pseConfig = null;        try {            XMLElement param = (XMLElement) advertisement.getServiceParam(PeerGroup.membershipClassID);            if (param != null) {                // XXX 20041027 backwards compatibility                param.addAttribute("type", PSEConfigAdv.getAdvertisementType());                pseConfig = (PSEConfigAdv) AdvertisementFactory.newAdvertisement(param);            }        } catch (Exception failure) {            if (Logging.SHOW_WARNING && LOG.isLoggable(Level.WARNING)) {                LOG.log(Level.WARNING, "Problem reading pse configuration", failure);            }        }        if (null == pseConfig) {            if (Logging.SHOW_CONFIG && LOG.isLoggable(Level.CONFIG)) {                LOG.config("PSE Config advertisement missing, making a new one.");            }            // restore default values.            pseConfig = (PSEConfigAdv) AdvertisementFactory.newAdvertisement(PSEConfigAdv.getAdvertisementType());            XMLDocument pseDoc = (XMLDocument) pseConfig.getDocument(MimeMediaType.XMLUTF8);            advertisement.putServiceParam(PeerGroup.membershipClassID, pseDoc);        }        // If we did not modify anything of importance or see anything wrong,        // leave the adv alone.        return reconf;    }    private boolean isValidInetAddress(String address) {        boolean found = false;        boolean loopback;        InetAddress[] ias;        try {            ias = InetAddress.getAllByName(address);        } catch (java.net.UnknownHostException notfound) {            return false;        }        for (Iterator la = IPUtils.getAllLocalAddresses(); la.hasNext() && !found;) {            for (InetAddress ia1 : ias) {                found |= ia1.equals(la.next());            }        }        loopback = true;        for (InetAddress ia1 : ias) {            loopback &= ia1.isLoopbackAddress();        }        return found || loopback;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -