Search in sources :

Example 41 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class I2PSessionIT method testSendAndRecieve.

public void testSendAndRecieve() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Destination d = I2PClientFactory.createClient().createDestination(out);
    I2PSession session = new I2PSessionImpl2(I2PAppContext.getGlobalContext(), new ByteArrayInputStream(out.toByteArray()), null);
    session.connect();
    session.setSessionListener(this);
    _s = new HashSet<String>();
    _s.add("a");
    _s.add("b");
    _s.add("c");
    _s.add("d");
    session.sendMessage(d, DataHelper.getASCII("a"));
    session.sendMessage(d, DataHelper.getASCII("b"));
    session.sendMessage(d, DataHelper.getASCII("c"));
    session.sendMessage(d, DataHelper.getASCII("d"));
    for (int i = 0; (i < 20) && (!_s.isEmpty()); i++) {
        Thread.sleep(1000);
    }
    assertTrue(_s.isEmpty());
}
Also used : Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 42 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class NamingServiceBean method getLookupAll.

/**
 *  @since 0.9.26
 */
public List<AddressBean> getLookupAll() {
    if (this.detail == null)
        return null;
    if (isDirect()) {
        // won't work for the published addressbook
        AddressBean ab = getLookup();
        if (ab != null)
            return Collections.singletonList(ab);
        return null;
    }
    Properties nsOptions = new Properties();
    List<Properties> propsList = new ArrayList<Properties>(4);
    nsOptions.setProperty("list", getFileName());
    List<Destination> dests = getNamingService().lookupAll(this.detail, nsOptions, propsList);
    if (dests == null)
        return null;
    List<AddressBean> rv = new ArrayList<AddressBean>(dests.size());
    for (int i = 0; i < dests.size(); i++) {
        AddressBean ab = new AddressBean(this.detail, dests.get(i).toBase64());
        ab.setProperties(propsList.get(i));
        rv.add(ab);
    }
    return rv;
}
Also used : Destination(net.i2p.data.Destination) ArrayList(java.util.ArrayList) Properties(java.util.Properties)

Example 43 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class NamingServiceBean method getLoadBookMessages.

/**
 *  Load addressbook and apply filter, returning messages about this.
 *  To control memory, don't load the whole addressbook if we can help it...
 *  only load what is searched for.
 */
@Override
public String getLoadBookMessages() {
    if (isDirect())
        return super.getLoadBookMessages();
    NamingService service = getNamingService();
    debug("Searching within " + service + " with filename=" + getFileName() + " and with filter=" + filter + " and with search=" + search);
    String message = "";
    try {
        LinkedList<AddressBean> list = new LinkedList<AddressBean>();
        Map<String, Destination> results;
        Properties searchProps = new Properties();
        // only blockfile needs this
        searchProps.setProperty("list", getFileName());
        if (filter != null) {
            String startsAt = filter.equals("0-9") ? "[0-9]" : filter;
            searchProps.setProperty("startsWith", startsAt);
        }
        if (isPrefiltered()) {
            // know the total number of results
            if (beginIndex > 0)
                searchProps.setProperty("skip", Integer.toString(beginIndex));
            int limit = 1 + endIndex - beginIndex;
            if (limit > 0)
                searchProps.setProperty("limit", Integer.toString(limit));
        }
        if (search != null && search.length() > 0)
            searchProps.setProperty("search", search.toLowerCase(Locale.US));
        results = service.getEntries(searchProps);
        debug("Result count: " + results.size());
        for (Map.Entry<String, Destination> entry : results.entrySet()) {
            String name = entry.getKey();
            if (filter != null && filter.length() > 0) {
                if (filter.equals("0-9")) {
                    char first = name.charAt(0);
                    if (first < '0' || first > '9')
                        continue;
                } else if (!name.toLowerCase(Locale.US).startsWith(filter.toLowerCase(Locale.US))) {
                    continue;
                }
            }
            if (search != null && search.length() > 0) {
                if (name.indexOf(search) == -1) {
                    continue;
                }
            }
            String destination = entry.getValue().toBase64();
            if (destination != null) {
                list.addLast(new AddressBean(name, destination));
            } else {
                // delete it too?
                System.err.println("Bad entry " + name + " in database " + service.getName());
            }
        }
        AddressBean[] array = list.toArray(new AddressBean[list.size()]);
        if (!(results instanceof SortedMap))
            Arrays.sort(array, sorter);
        entries = array;
        message = generateLoadMessage();
    } catch (RuntimeException e) {
        warn(e);
    }
    if (message.length() > 0)
        message = "<p id=\"filtered\">" + message + "</p>";
    return message;
}
Also used : Destination(net.i2p.data.Destination) Properties(java.util.Properties) LinkedList(java.util.LinkedList) NamingService(net.i2p.client.naming.NamingService) SortedMap(java.util.SortedMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 44 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class NamingServiceBean method getLookup.

public AddressBean getLookup() {
    if (this.detail == null)
        return null;
    if (isDirect()) {
        // go to some trouble to make this work for the published addressbook
        this.filter = this.detail.substring(0, 1);
        this.search = this.detail;
        // we don't want the messages, we just want to populate entries
        super.getLoadBookMessages();
        for (int i = 0; i < this.entries.length; i++) {
            if (this.search.equals(this.entries[i].getName()))
                return this.entries[i];
        }
        return null;
    }
    Properties nsOptions = new Properties();
    Properties outProps = new Properties();
    nsOptions.setProperty("list", getFileName());
    Destination dest = getNamingService().lookup(this.detail, nsOptions, outProps);
    if (dest == null)
        return null;
    AddressBean rv = new AddressBean(this.detail, dest.toBase64());
    rv.setProperties(outProps);
    return rv;
}
Also used : Destination(net.i2p.data.Destination) Properties(java.util.Properties)

Example 45 with Destination

use of net.i2p.data.Destination in project i2p.i2p by i2p.

the class TCBShare method updateShareOpts.

/**
 * store to cache
 */
public void updateShareOpts(Connection con) {
    Destination dest = con.getRemotePeer();
    if (dest == null)
        return;
    if (con.getAckedPackets() <= 0)
        return;
    ConnectionOptions opts = con.getOptions();
    if (opts == null)
        return;
    int old = -1;
    int oldw = -1;
    int oldDev = -1;
    Entry e = _cache.get(dest);
    if (e == null || e.isExpired()) {
        e = new Entry(opts.getRTT(), opts.getWindowSize(), opts.getRTTDev());
        _cache.put(dest, e);
    } else {
        synchronized (e) {
            old = e.getRTT();
            oldw = e.getWindowSize();
            oldDev = e.getRTTDev();
            e.setRTT(opts.getRTT());
            e.setWindowSize(opts.getWindowSize());
            e.setRTTDev(opts.getRTTDev());
        }
    }
    if (_log.shouldLog(Log.DEBUG)) {
        _log.debug("To cache: " + con.getSession().getMyDestination().calculateHash().toBase64().substring(0, 4) + '-' + dest.calculateHash().toBase64().substring(0, 4) + " old: " + old + " con: " + opts.getRTT() + " new: " + e.getRTT() + " oldDev: " + oldDev + " conDev: " + opts.getRTTDev() + " newDev: " + e.getRTTDev() + " oldw: " + oldw + " conw: " + opts.getWindowSize() + " neww: " + e.getWindowSize());
    }
}
Also used : Destination(net.i2p.data.Destination)

Aggregations

Destination (net.i2p.data.Destination)149 IOException (java.io.IOException)46 DataFormatException (net.i2p.data.DataFormatException)33 Properties (java.util.Properties)29 I2PException (net.i2p.I2PException)26 Hash (net.i2p.data.Hash)18 ArrayList (java.util.ArrayList)13 File (java.io.File)12 I2PSessionException (net.i2p.client.I2PSessionException)12 SigType (net.i2p.crypto.SigType)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 I2PSession (net.i2p.client.I2PSession)10 I2PSocket (net.i2p.client.streaming.I2PSocket)10 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)7 I2PClient (net.i2p.client.I2PClient)7 I2PSocketOptions (net.i2p.client.streaming.I2PSocketOptions)7 Test (org.junit.Test)6