java.lang.Object
net.i2p.client.naming.HostTxtEntry
A hostname, b64 destination, and optional properties. Includes methods to sign and verify the entry. Used by addressbook to parse subscription data, and by i2ptunnel to generate signed metadata.
Field Summary
Modifier and TypeFieldDescriptionstatic final StringAction value: add a new destination.static final StringAction value: add a new hostname.static final StringAction value: add a subdomain entry.static final StringAction value: change an existing destination.static final StringAction value: change an existing hostname.static final StringAction value: remove an entry.static final StringAction value: remove all entries.static final StringAction value: update an existing entry.private final StringThe destination, as text.private booleanFalse if the line was malformed.private booleanTrue once the entry has been checked.static final charSeparator between name and destination in the hosts.txt line.private final StringThe subscription's name.static final StringProperty key for the action type (e.g.static final StringProperty key for the date timestamp (seconds since epoch).static final StringProperty key for the destination Base64 string.static final StringProperty key for the expiry time.static final StringProperty key for the hostname.static final StringProperty key for the old destination (used in change operations).static final StringProperty key for the old hostname (used in rename operations).static final StringProperty key for the old signature for inner verification.static final charSeparator between individual properties.static final StringProperty key for the signature.private final OrderedPropertiesTiming and other properties of the entry.static final StringSeparator between the destination part and the properties part.Constructor Summary
ConstructorsConstructorDescriptionHostTxtEntry(String sprops) A 'remove' entry.HostTxtEntry(String name, String dest) Create a new host text entry with name and destination, no properties.HostTxtEntry(String name, String dest, String sprops) Create a new host text entry with name, destination, and serialized properties.HostTxtEntry(String name, String dest, OrderedProperties props) Create a new host text entry with optional properties.Method Summary
Modifier and TypeMethodDescriptionbooleanCompares Destination only, not properties.getDest()Return the Base64 destination.getName()The hostname mapped by this entry, or null for a 'remove' entry.getProps()Return the properties, or null.inthashCode()booleanVerify with the "olddest" property's public key using the "oldsig" property.booleanVerify with the "dest" property's public key using the "sig" property.booleanVerify with the dest public key using the "sig" property.private static OrderedPropertiesparseProps(String line) Part after the #!.voidsign(SigningPrivateKey spk) Sign and set the "sig" property Must have been constructed with non-null properties.voidSign and set the "oldsig" property Must have been constructed with non-null properties.private voidsignIt(SigningPrivateKey spk, String sigprop) Sign the entry and set the specified signature property.voidSign as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] Must have been constructed with non-null properties.voidwrite(BufferedWriter out) Write as a standard line name=dest[#!k1=v1#k2=v2...] Includes newline.voidWrite as a standard line name=dest[#!k1=v1#k2=v2...] Does not include newline.voidwriteProps(Writer out) Write the props part (if any) only, without newline.private voidwriteProps(Writer out, boolean omitSig, boolean omitOldSig) Write the props part (if any) only, without newline.voidwriteRemove(Writer out) Write as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] This works whether constructed with name and dest, or just properties.voidWrite as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] This works whether constructed with name and dest, or just properties.
Field Details
name
The subscription's name.dest
The destination, as text.props
Timing and other properties of the entry.isValidated
private boolean isValidatedTrue once the entry has been checked.isValid
private boolean isValidFalse if the line was malformed.KV_SEPARATOR
public static final char KV_SEPARATORSeparator between name and destination in the hosts.txt line.- See Also:
PROPS_SEPARATOR
Separator between the destination part and the properties part.- See Also:
PROP_SEPARATOR
public static final char PROP_SEPARATORSeparator between individual properties.- See Also:
PROP_ACTION
Property key for the action type (e.g. adddest, remove).- See Also:
PROP_DATE
Property key for the date timestamp (seconds since epoch).- See Also:
PROP_DEST
Property key for the destination Base64 string.- See Also:
PROP_EXPIRES
Property key for the expiry time.- See Also:
PROP_NAME
PROP_OLDDEST
Property key for the old destination (used in change operations).- See Also:
PROP_OLDNAME
Property key for the old hostname (used in rename operations).- See Also:
PROP_OLDSIG
Property key for the old signature for inner verification.- See Also:
PROP_SIG
ACTION_ADDDEST
Action value: add a new destination.- See Also:
ACTION_ADDNAME
Action value: add a new hostname.- See Also:
ACTION_ADDSUBDOMAIN
Action value: add a subdomain entry.- See Also:
ACTION_CHANGEDEST
Action value: change an existing destination.- See Also:
ACTION_CHANGENAME
Action value: change an existing hostname.- See Also:
ACTION_REMOVE
Action value: remove an entry.- See Also:
ACTION_REMOVEALL
Action value: remove all entries.- See Also:
ACTION_UPDATE
Action value: update an existing entry.- See Also:
Constructor Details
HostTxtEntry
HostTxtEntry
Create a new host text entry with name, destination, and serialized properties.- Parameters:
name- the hostname, null for a 'remove' entrydest- the Base64 destinationsprops- line part after the #!, non-null- Throws:
IllegalArgumentException- on dup key in sprops and other errors
HostTxtEntry
A 'remove' entry. Name and Dest will be null.- Parameters:
sprops- line part after the #!, non-null- Throws:
IllegalArgumentException- on dup key in sprops and other errors
HostTxtEntry
Create a new host text entry with optional properties.- Parameters:
name- the hostname, null for a 'remove' entrydest- the Base64 destinationprops- may be null
Method Details
getName
The hostname mapped by this entry, or null for a 'remove' entry.- Returns:
- the hostname, or null for a 'remove' entry
getDest
getProps
parseProps
Part after the #!.- Parameters:
line- part after the #!- Returns:
- the parsed properties
- Throws:
IllegalArgumentException- on dup key and other errors
write
Write as a standard line name=dest[#!k1=v1#k2=v2...] Includes newline.- Parameters:
out- the writer to write to- Throws:
IOException- if writing fails
write
Write as a standard line name=dest[#!k1=v1#k2=v2...] Does not include newline.- Parameters:
out- the writer to write to- Throws:
IOException- if writing fails
writeRemoveLine
Write as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] This works whether constructed with name and dest, or just properties. Includes newline. Must have been constructed with non-null properties.- Parameters:
out- the writer to write to- Throws:
IOException- if writing fails
writeRemove
Write as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] This works whether constructed with name and dest, or just properties. Does not include newline. Must have been constructed with non-null properties.- Parameters:
out- the writer to write to- Throws:
IOException- if writing fails
writeProps
Write the props part (if any) only, without newline.- Parameters:
out- the writer to write to- Throws:
IOException- if writing fails
writeProps
Write the props part (if any) only, without newline.- Parameters:
out- the writer to write toomitSig- true to skip the "sig" propertyomitOldSig- true to skip the "oldsig" property- Throws:
IOException- if writing fails
hasValidSig
public boolean hasValidSig()Verify with the dest public key using the "sig" property.- Returns:
- whether valid sig is present
hasValidInnerSig
public boolean hasValidInnerSig()Verify with the "olddest" property's public key using the "oldsig" property.- Returns:
- whether valid inner sig is present
hasValidRemoveSig
public boolean hasValidRemoveSig()Verify with the "dest" property's public key using the "sig" property.- Returns:
- whether valid remove sig is present
hashCode
equals
sign
Sign and set the "sig" property Must have been constructed with non-null properties.- Parameters:
spk- the signing key the entry's destination is signed with, so a receiver can tell the entry was issued by the destination itself
signInner
Sign and set the "oldsig" property Must have been constructed with non-null properties.- Parameters:
spk- the signing key used for the "oldsig" signature, which covers the entry as previously published and lets the server tell an unchanged entry from one that has since been replaced
signRemove
Sign as a "remove" line #!dest=dest#name=name#k1=v1#sig=sig...] Must have been constructed with non-null properties.- Parameters:
spk- the signing key the removal line is signed with, identifying the key that published the entry being withdrawn
signIt
Sign the entry and set the specified signature property.- Parameters:
spk- the signing private keysigprop- The signature property to set