Added the option to retrieve only the own seed or a seleceted seed

(selected by peer-hash) in the /yacy/seedlist.[json/xml] api.
Added also a xml-version of the servlet.
The own seed can be retrieved i.e. with
http://localhost:8090/yacy/seedlist.xml?my=
http://localhost:8090/yacy/seedlist.json?my=
and any other peer can be selected with
http://localhost:8090/yacy/seedlist.xml?id=<peerhash>
http://localhost:8090/yacy/seedlist.json?id=<peerhash>
pull/1/head
Michael Peter Christen 10 years ago
parent ffc259c944
commit b93ea4e2a6

@ -50,13 +50,24 @@ public final class seedlist {
boolean nodeonly = post == null || !post.containsKey("node") ? false : post.getBoolean("node");
boolean includeme = post == null || !post.containsKey("me") ? true : post.getBoolean("me");
boolean addressonly = post == null || !post.containsKey("address") ? false : post.getBoolean("address");
String peername = post == null ? null : post.get("peername");
final ArrayList<Seed> v = sb.peers.getSeedlist(maxcount, includeme, nodeonly, minversion);
String peername = post == null ? null : post.containsKey("my") ? sb.peers.myName() : post.get("peername");
final ArrayList<Seed> v;
if (post != null && post.containsKey("my")) {
v = new ArrayList<Seed>(1);
v.add(sb.peers.mySeed());
} else if (post != null && post.containsKey("id")) {
v = new ArrayList<Seed>(1);
Seed s = sb.peers.get(post.get("id"));
if (s != null) v.add(s);
} else {
v= sb.peers.getSeedlist(maxcount, includeme, nodeonly, minversion);
}
final serverObjects prop = new serverObjects();
// write simple-encoded seed lines or json
String EXT = header.get("EXT");
boolean json = EXT != null && EXT.equals("json");
boolean xml = EXT != null && EXT.equals("xml");
if (json) {
// check for JSONP
@ -93,6 +104,32 @@ public final class seedlist {
count++;
}
prop.put("peers_" + (count - 1) + "_c", 0);
prop.put("peers", count);
} else if (xml) {
int count = 0;
for (int i = 0; i < v.size(); i++) {
Seed seed = v.get(i);
if (peername != null && !peername.equals(seed.getName())) continue;
prop.putXML("peers_" + count + "_map_0_k", Seed.HASH);
prop.putXML("peers_" + count + "_map_0_v", seed.hash);
prop.put("peers_" + count + "_map_0_c", 1);
Map<String, String> map = seed.getMap();
int c = 1;
if (!addressonly) {
for (Map.Entry<String, String> m: map.entrySet()) {
prop.putXML("peers_" + count + "_map_" + c + "_k", m.getKey());
prop.putXML("peers_" + count + "_map_" + c + "_v", m.getValue());
c++;
}
}
prop.putXML("peers_" + count + "_map_" + c + "_k", "Address");
prop.putXML("peers_" + count + "_map_" + c + "_v", seed.getPublicAddress());
prop.put("peers_" + count + "_map_" + c + "_c", 0);
prop.put("peers_" + count + "_map", c + 1);
count++;
}
prop.put("peers_" + (count - 1) + "_c", 0);
prop.put("peers", count);
} else {

@ -0,0 +1,10 @@
<?xml version="1.0"?>
<peers>
#{peers}#
<seed>
#{map}#
<#[k]#>#[v]#</#[k]#>
#{/map}#
</seed>
#{/peers}#
</peers>
Loading…
Cancel
Save