61 |
return result; |
return result; |
62 |
} |
} |
63 |
|
|
64 |
public BlockId get(PointerId id) |
public BlockId get(PointerId id) |
65 |
|
throws IOException, GeneralSecurityException { |
66 |
|
PointerBlock b = getPointerBlock(id); |
67 |
|
if(b == null) return null; |
68 |
|
return b.getTarget(); |
69 |
|
} |
70 |
|
|
71 |
|
public PointerBlock getPointerBlock(PointerId id) |
72 |
throws IOException, GeneralSecurityException { |
throws IOException, GeneralSecurityException { |
73 |
if(dbg) p("Get: "+id); |
if(dbg) p("Get: "+id); |
74 |
|
|
75 |
Collector c = db.get(id.toString()).block(); |
Collector c = db.get(id.toString()).block(); |
76 |
long maxstamp = 0; |
long maxstamp = 0; |
77 |
BlockId result = null; |
PointerBlock result = null; |
78 |
for(Iterator i=c.iterator(); i.hasNext();) { |
for(Iterator i=c.iterator(); i.hasNext();) { |
79 |
IndexedPool.Mapping m = (IndexedPool.Mapping)i.next(); |
IndexedPool.Mapping m = (IndexedPool.Mapping)i.next(); |
80 |
if(dbg) p("Process: "+m.block+" "+m.value); |
if(dbg) p("Process: "+m.block+" "+m.value); |
97 |
|
|
98 |
if(p.getPointer().equals(id) && |
if(p.getPointer().equals(id) && |
99 |
p.getTimestamp() == timestamp) { |
p.getTimestamp() == timestamp) { |
100 |
result = p.getTarget(); |
result = p; |
101 |
maxstamp = timestamp; |
maxstamp = timestamp; |
102 |
} |
} |
103 |
} |
} |
108 |
|
|
109 |
public void set(PointerId id, BlockId target, KeyPair keyPair) |
public void set(PointerId id, BlockId target, KeyPair keyPair) |
110 |
throws IOException, GeneralSecurityException { |
throws IOException, GeneralSecurityException { |
111 |
|
set(id, target, keyPair, null); |
112 |
|
} |
113 |
|
|
114 |
|
public void set(PointerId id, BlockId target, KeyPair keyPair, |
115 |
|
String newName) |
116 |
|
throws IOException, GeneralSecurityException { |
117 |
// XXX this assumes that the computer clock |
// XXX this assumes that the computer clock |
118 |
// is always set correctly: if there is an existing |
// is always set correctly: if there is an existing |
119 |
// pointer block with a later timestamp (because |
// pointer block with a later timestamp (because |
130 |
timestamp + "\n" + |
timestamp + "\n" + |
131 |
target.toString(); |
target.toString(); |
132 |
|
|
133 |
|
if(newName != null) { |
134 |
|
if(newName.indexOf("\n") >= 0) |
135 |
|
throw new IllegalArgumentException("Newline in ptr name"); |
136 |
|
data += "\n" + newName; |
137 |
|
} |
138 |
|
|
139 |
Signature s = Signature.getInstance("SHA1withDSA"); |
Signature s = Signature.getInstance("SHA1withDSA"); |
140 |
s.initSign(keyPair.getPrivate()); |
s.initSign(keyPair.getPrivate()); |
141 |
s.update(data.getBytes("US-ASCII")); |
s.update(data.getBytes("US-ASCII")); |