Profiles: Create profiles in the nonblocking path

thanks energy52
This commit is contained in:
zzz
2020-08-14 12:54:39 +00:00
parent d7b512ca9a
commit 07fc66ccff
4 changed files with 61 additions and 6 deletions

View File

@ -1,7 +1,10 @@
2020-08-14 zzz
* Profiles: Create profiles in the nonblocking path
2020-08-10 idk 2020-08-10 idk
* Replace all icons with icons from a single consistent source/style, icons * Replace all icons with icons from a single consistent source/style, icons
used from FontAwesome suggested by design team and selected and edited by used from FontAwesome suggested by design team and selected and edited by
Sadie. Sadie.
2020-08-01 zzz 2020-08-01 zzz
* Debian: Support libjson-simple-java 3 for bullseye * Debian: Support libjson-simple-java 3 for bullseye

View File

@ -18,10 +18,10 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11; public final static long BUILD = 12;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "-rc";
public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA; public final static String FULL_VERSION = VERSION + "-" + BUILD + EXTRA;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + FULL_VERSION); System.out.println("I2P Router version: " + FULL_VERSION);

View File

@ -361,10 +361,11 @@ public class ProfileManagerImpl implements ProfileManager {
/** /**
* Non-blocking. * Non-blocking.
* @return null if the profile doesn't exist, or the fetch would have blocked * Creates a new profile if it didn't exist.
* @return null if the fetch or create would have blocked
* @since 0.8.12 * @since 0.8.12
*/ */
private PeerProfile getProfileNonblocking(Hash peer) { private PeerProfile getProfileNonblocking(Hash peer) {
return _context.profileOrganizer().getProfileNonblocking(peer); return _context.profileOrganizer().getOrCreateProfileNonblocking(peer);
} }
} }

View File

@ -132,6 +132,15 @@ public class ProfileOrganizer {
_reorganizeLock.readLock().unlock(); _reorganizeLock.readLock().unlock();
} }
/**
* Get the lock if we can. Non-blocking.
* @return true if the lock was acquired
* @since 0.9.47
*/
private boolean tryWriteLock() {
return _reorganizeLock.writeLock().tryLock();
}
/** @return true if the lock was acquired */ /** @return true if the lock was acquired */
private boolean getWriteLock() { private boolean getWriteLock() {
try { try {
@ -189,6 +198,48 @@ public class ProfileOrganizer {
return null; return null;
} }
/**
* Retrieve the profile for the given peer, if one exists.
* If it does not exist and it can get the lock, it will create and return a new profile.
* Non-blocking. Returns null if a reorganize is happening.
* @since 0.9.47
*/
PeerProfile getOrCreateProfileNonblocking(Hash peer) {
if (peer.equals(_us)) {
if (_log.shouldWarn())
_log.warn("Who wanted our own profile?", new Exception("I did"));
return null;
}
if (!tryReadLock())
return null;
PeerProfile rv;
try {
rv = locked_getProfile(peer);
} finally { releaseReadLock(); }
if (rv != null)
return rv;
rv = new PeerProfile(_context, peer);
rv.coalesceStats();
if (!tryWriteLock())
return null;
try {
// double check
PeerProfile old = locked_getProfile(peer);
if (old != null)
return old;
_notFailingPeers.put(peer, rv);
_notFailingPeersList.add(peer);
// Add to high cap only if we have room. Don't add to Fast; wait for reorg.
if (_thresholdCapacityValue <= rv.getCapacityValue() &&
isSelectable(peer) &&
_highCapacityPeers.size() < getMaximumHighCapPeers()) {
_highCapacityPeers.put(peer, rv);
}
_strictCapacityOrder.add(rv);
} finally { releaseWriteLock(); }
return rv;
}
/** /**
* Add the new profile, returning the old value (or null if no profile existed) * Add the new profile, returning the old value (or null if no profile existed)
* *