java.lang.Object
net.i2p.router.JobImpl
net.i2p.router.sybil.Analysis
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA dummy list that always returns true on add.private classLoad the persisted blocklist and tell the router.private static classOrders router infos by distance from us in the keyspace.Field Summary
Modifier and TypeFieldDescriptionprivate BanLoggerRecords why routers were banned.private final ClientAppManagerManager that starts and stops this analysis.private final RouterContextThe router context.Family names exempt from the /24 points.private final LogLogger for the sybil analysis.private final PersistSybilSaves the analysis results to disk.private ClientAppStateCurrent state of the analysis client app.private booleanWhether an analysis pass has completed.static final StringThe name we register with the ClientAppManager.private static final BigIntegerOne past the largest routing key, for wrap-around math.private static final StringBundle holding the translated console strings.private static final longOne day in milliseconds.static final booleanDefault is blocking enabled.static final doubleDefault block threshold.static final longDefault block time.static final longDefault scan frequency.static final longDefault remove time.private final DecimalFormatFormatter for the displayed scores.private static final byte[]IPv6 loopback address, never scored.private static final byte[]NAT64 prefix seen from i2pd routers.static final intMaximum entries to process.static final floatMinimum points to block.static final doubleMinimum close value for family detection.private static final longShortest interval between analysis runs, one hour.private static final longRouter uptime needed before the first run is 75 minutes.private static final doubleMultiplier for points against our own key.private static final doubleMultiplier for the pair distance points.static final intMaximum pairs to analyze.private static final doublePoints added for a family mismatch.private static final doublePoints added when our family does not match.private static final doublePoints added for a different router version.private static final doublePoints added for a banlisted router, below the permanent ban threshold.private static final doublePoints removed for routers in the same family.private static final doublePoints removed for a verified family match.private static final doublePoints added for a recently seen router.private static final doublePoints removed when neither router is a floodfill.private static final doublePoints removed when our family matches.private static final doublePoints added for an unreachable router.private static final doublePoints for a US /16 pair.private static final doublePoints for a US /24 pair.private static final doublePoints for a US /32 pair.private static final doublePoints for a US IPv6 /48 pair.private static final doublePoints for a US IPv6 /64 pair.private static final doublePoints for a /16 pair, scaled by group size.private static final doublePoints for a /24 pair, scaled by group size.private static final doublePoints for a /32 pair, scaled by group size.private static final doublePoints for an IPv6 /48 pair.private static final doublePoints for an IPv6 /64 pair.static final StringProperty to enable blocking.static final StringProperty to set the block period.static final StringProperty to set the scan frequency.static final StringProperty to analyze all peers.static final StringProperty to set the delete old period.static final StringProperty to set the threshold.static final longShort remove time.private static final doubleMultiplier for the version difference points.Constructor Summary
ConstructorsModifierConstructorDescriptionprivateAnalysis(RouterContext ctx, ClientAppManager mgr, String[] args) UsegetInstance(RouterContext)instead.Method Summary
Modifier and TypeMethodDescriptionprivate StringTranslates a console string.private StringTranslate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.private voidAdds scored points for one router.voidaddProfilePoints(List<RouterInfo> ris, Map<Hash, Points> points) Analyzes router profiles and adds Sybil points for banlisted, newly observed, or poorly performing routers.voidaddVersionPoints(List<RouterInfo> ris, Map<Hash, Points> points) Analyzes router versions and adds Sybil points for old, unreachable, or non-floodfill routers.backgroundAnalysis(boolean includeAll) Analyze threats.private static doublebiLog2(BigInteger a) For debugging http://forums.sun.com/thread.jspa?threadID=597652Map<Integer, List<RouterInfo>> calculateIPGroups16(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their /16 subnet to identify routers in the same /16 network.Map<Integer, List<RouterInfo>> calculateIPGroups24(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their /24 subnet to identify routers in the same /24 network.Map<Integer, List<RouterInfo>> calculateIPGroups32(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their IP address to identify routers sharing the same IP.Map<Long, List<RouterInfo>> calculateIPGroups48(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their IPv6 /48 subnet to identify routers in the same /48 network.Map<Long, List<RouterInfo>> calculateIPGroups64(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their IPv6 /64 subnet to identify routers in the same /64 network.Map<String, List<RouterInfo>> calculateIPGroupsFamily(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their router family to identify routers in the same family.voidcalculateIPGroupsUs(List<RouterInfo> ris, Map<Hash, Points> points, List<RouterInfo> ri32, List<RouterInfo> ri24, List<RouterInfo> ri16, List<RouterInfo> ri64, List<RouterInfo> ri48) Categorize routers by their proximity to our IP address, grouping them by /32, /24, /16 for IPv4 and /64, /48 for IPv6.doublecalculatePairDistance(List<RouterInfo> ris, Map<Hash, Points> points, List<Pair> pairs) Calculate average pairwise distance between floodfills and identifies routers that are unusually close to each other.voidcalculateRouterInfo(Hash us, String usName, List<RouterInfo> ris, Map<Hash, Points> points) Build the version comparison report.private voidchangeState(ClientAppState state) Records the new app state and notifies the console manager.private static doubleclosestDistance(Hash h, List<RouterInfo> ris) Finds the keyspace distance to the nearest listed router.private voiddoBlocking(Map<Hash, Points> points) Blocklist and Banlist if configured.getAllRouters(Hash us) Returns all routers in the network DB, excluding our own router.doublegetAvgMinDist(List<RouterInfo> ris) Calculates the average minimum distance from 200 random routing keys to the closest router in the provided list.Display name for this application.getFloodfills(Hash us) Returns all floodfill routers, excluding our own router.static AnalysisgetInstance(RouterContext ctx) Singleton Analysis instance, creating it if necessary.private static byte[]getIP(RouterInfo ri) IPv4 only.private static byte[]getIPv6(RouterInfo ri) IPv6 only.getName()Application name.Persistence handler for storing and retrieving Sybil analysis data.getState()Current state of this application.voidrun()Executes the background Sybil analysis, stores results, and removes old data.voidrunJob()//// begin Job methodsvoidschedule()Schedules the next Sybil analysis run based on configured frequency, router uptime, and previous run time.voidStops the Sybil analysis service and changes state to STOPPED.voidstartup()Initializes and starts the Sybil analysis service.Methods inherited from class JobImpl
dropped, getContext, getJobId, getMadeReadyOn, getTiming, madeReady, requeue, toStringModifier and TypeMethodDescriptionvoiddropped()Default implementation does nothing.final RouterContextThe router context that this job belongs to.longgetJobId()The unique job ID for this job.longThe timestamp when this job was last made ready for execution.The timing object for this job.voidmadeReady(long now) For JobQueue only, not for external use.protected voidrequeue(long delayMs) Requeue this job to run after the specified delay.toString()
Field Details
_context
The router context._log
Logger for the sybil analysis._banLogger
Records why routers were banned._cmgr
Manager that starts and stops this analysis._persister
Saves the analysis results to disk._state
Current state of the analysis client app.fmt
Formatter for the displayed scores._wasRun
private boolean _wasRunWhether an analysis pass has completed._familyExemptPoints24
APP_NAME
The name we register with the ClientAppManager.- See Also:
PROP_FREQUENCY
Property to set the scan frequency.- See Also:
PROP_THRESHOLD
Property to set the threshold.- See Also:
PROP_BLOCK
PROP_NONFF
PROP_BLOCKTIME
Property to set the block period.- See Also:
PROP_REMOVETIME
Property to set the delete old period.- See Also:
MIN_FREQUENCY
private static final long MIN_FREQUENCYShortest interval between analysis runs, one hour.- See Also:
MIN_UPTIME
private static final long MIN_UPTIMERouter uptime needed before the first run is 75 minutes.- See Also:
DEFAULT_FREQUENCY
PAIRMAX
MAX
POINTS32
private static final double POINTS32Points for a /32 pair, scaled by group size.- See Also:
POINTS24
private static final double POINTS24Points for a /24 pair, scaled by group size.- See Also:
POINTS16
private static final double POINTS16Points for a /16 pair, scaled by group size.- See Also:
POINTS_US32
POINTS_US24
POINTS_US16
POINTS_V6_US64
private static final double POINTS_V6_US64Points for a US IPv6 /64 pair.- See Also:
POINTS_V6_US48
private static final double POINTS_V6_US48Points for a US IPv6 /48 pair.- See Also:
POINTS64
POINTS48
POINTS_FAMILY
private static final double POINTS_FAMILYPoints removed for routers in the same family.- See Also:
POINTS_FAMILY_VERIFIED
private static final double POINTS_FAMILY_VERIFIEDPoints removed for a verified family match.- See Also:
POINTS_NONFF
private static final double POINTS_NONFFPoints removed when neither router is a floodfill.- See Also:
POINTS_BAD_FAMILY
private static final double POINTS_BAD_FAMILYPoints added for a family mismatch.- See Also:
POINTS_BAD_OUR_FAMILY
private static final double POINTS_BAD_OUR_FAMILYPoints added when our family does not match.- See Also:
POINTS_OUR_FAMILY
private static final double POINTS_OUR_FAMILYPoints removed when our family matches.- See Also:
POINTS_BAD_VERSION
private static final double POINTS_BAD_VERSIONPoints added for a different router version.- See Also:
POINTS_UNREACHABLE
private static final double POINTS_UNREACHABLEPoints added for an unreachable router.- See Also:
POINTS_NEW
private static final double POINTS_NEWPoints added for a recently seen router.- See Also:
POINTS_BANLIST
private static final double POINTS_BANLISTPoints added for a banlisted router, below the permanent ban threshold.- See Also:
MIN_CLOSE
public static final double MIN_CLOSEMinimum close value for family detection.- See Also:
PAIR_DISTANCE_FACTOR
private static final double PAIR_DISTANCE_FACTORMultiplier for the pair distance points.- See Also:
OUR_KEY_FACTOR
private static final double OUR_KEY_FACTORMultiplier for points against our own key.- See Also:
VERSION_FACTOR
private static final double VERSION_FACTORMultiplier for the version difference points.- See Also:
DEFAULT_BLOCK
DEFAULT_BLOCK_THRESHOLD
public static final double DEFAULT_BLOCK_THRESHOLDDefault block threshold.- See Also:
DEFAULT_BLOCK_TIME
DEFAULT_REMOVE_TIME
SHORT_REMOVE_TIME
MIN_BLOCK_POINTS
IPV6_LOCALHOST
private static final byte[] IPV6_LOCALHOSTIPv6 loopback address, never scored.IPV6_NAT64
private static final byte[] IPV6_NAT64NAT64 prefix seen from i2pd routers.BI_MAX
One past the largest routing key, for wrap-around math.DAY
BUNDLE_NAME
Bundle holding the translated console strings.- See Also:
Constructor Details
Analysis
UsegetInstance(RouterContext)instead.- Parameters:
ctx- the router contextmgr- the client app manager the app is registered withargs- not used, may be null
Method Details
getInstance
Singleton Analysis instance, creating it if necessary.- Parameters:
ctx- the router context- Returns:
- non-null, creates new if not already registered
getPersister
Persistence handler for storing and retrieving Sybil analysis data.- Returns:
- the PersistSybil instance used by this analysis
runJob
run
startup
shutdown
getState
Current state of this application.getName
getDisplayName
Display name for this application.- Specified by:
getDisplayNamein interfaceClientApp- Returns:
- the display name
"Sybil Analyzer"
changeState
Records the new app state and notifies the console manager.- Parameters:
state- the new state of the client app
schedule
public void schedule()Schedules the next Sybil analysis run based on configured frequency, router uptime, and previous run time.addPoints
getFloodfills
Returns all floodfill routers, excluding our own router.- Parameters:
us- our router hash to exclude from the results- Returns:
- list of floodfill RouterInfo objects
getAllRouters
Returns all routers in the network DB, excluding our own router.- Parameters:
us- our router hash to exclude from the results- Returns:
- list of all RouterInfo objects
getAvgMinDist
Calculates the average minimum distance from 200 random routing keys to the closest router in the provided list.- Parameters:
ris- the list of router infos to analyze- Returns:
- the average minimum distance in logarithmic scale (base 2)
backgroundAnalysis
doBlocking
calculatePairDistance
public double calculatePairDistance(List<RouterInfo> ris, Map<Hash, Points> points, List<Pair> pairs) Calculate average pairwise distance between floodfills and identifies routers that are unusually close to each other.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil pointspairs- out parameter, sorted list of close router pairs- Returns:
- the mean pairwise XOR distance across the routers analyzed
closestDistance
Finds the keyspace distance to the nearest listed router.- Parameters:
h- the router hashris- routers ordered by distance- Returns:
- the smallest distance
getIP
IPv4 only.- Parameters:
ri- the router whose addresses are scanned- Returns:
- the first 4-byte address, or null if the router has none
getIPv6
IPv6 only.- Parameters:
ri- the router whose addresses are scanned- Returns:
- the IPv6, skipping the localhost and NAT64 forms i2pd gets wrong, or null when there is none
calculateIPGroupsUs
public void calculateIPGroupsUs(List<RouterInfo> ris, Map<Hash, Points> points, List<RouterInfo> ri32, List<RouterInfo> ri24, List<RouterInfo> ri16, List<RouterInfo> ri64, List<RouterInfo> ri48) Categorize routers by their proximity to our IP address, grouping them by /32, /24, /16 for IPv4 and /64, /48 for IPv6.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil pointsri32- out parameter for routers with same IP as usri24- out parameter for routers in same /24 as usri16- out parameter for routers in same /16 as usri64- out parameter for routers in same IPv6 /64 as usri48- out parameter for routers in same IPv6 /48 as us
calculateIPGroups32
public Map<Integer, List<RouterInfo>> calculateIPGroups32(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their IP address to identify routers sharing the same IP.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points- Returns:
- map of IP address (as Integer) to list of routers with that IP
calculateIPGroups24
public Map<Integer, List<RouterInfo>> calculateIPGroups24(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their /24 subnet to identify routers in the same /24 network.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points- Returns:
- map of /24 network (as Integer) to list of routers in that network
calculateIPGroups16
public Map<Integer, List<RouterInfo>> calculateIPGroups16(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their /16 subnet to identify routers in the same /16 network.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points- Returns:
- map of /16 network (as Integer) to list of routers in that network
calculateIPGroups64
public Map<Long, List<RouterInfo>> calculateIPGroups64(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their IPv6 /64 subnet to identify routers in the same /64 network.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points- Returns:
- map of IPv6 /64 network (as Long) to list of routers in that network
calculateIPGroups48
public Map<Long, List<RouterInfo>> calculateIPGroups48(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their IPv6 /48 subnet to identify routers in the same /48 network.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points- Returns:
- map of IPv6 /48 network (as Long) to list of routers in that network
calculateIPGroupsFamily
public Map<String, List<RouterInfo>> calculateIPGroupsFamily(List<RouterInfo> ris, Map<Hash, Points> points) Categorize routers by their router family to identify routers in the same family. Routers in verified families receive fewer points.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points- Returns:
- map of family name to list of routers in that family
addProfilePoints
Analyzes router profiles and adds Sybil points for banlisted, newly observed, or poorly performing routers.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points
addVersionPoints
Analyzes router versions and adds Sybil points for old, unreachable, or non-floodfill routers.- Parameters:
ris- the list of router infos to analyzepoints- map to accumulate sybil points
calculateRouterInfo
public void calculateRouterInfo(Hash us, String usName, List<RouterInfo> ris, Map<Hash, Points> points) Build the version comparison report.- Parameters:
us- the local router hashusName- the local router's display name, already HTML escapedris- will be re-sorted in placepoints- map of points per hash
biLog2
For debugging http://forums.sun.com/thread.jspa?threadID=597652- Parameters:
a- the value to take the base 2 logarithm of- Returns:
- the base 2 logarithm of a, as a double
_t
_t
Translate a string with a parameter This is a lot more expensive than _t(s), so use sparingly.- Parameters:
s- string to be translated containing {0} The {0} will be replaced by the parameter. Single quotes must be doubled, i.e. ' -> '' in the string.o- parameter, not translated. To translate parameter also, use _t("foo {0} bar", _t("baz")) Do not double the single quotes in the parameter. Use autoboxing to call with ints, longs, floats, etc.- Returns:
- the translated string, with {0} replaced by the parameter