-
Notifications
You must be signed in to change notification settings - Fork 23
sets spaceAvailable false if ALLOCs fail and contact not seen in 24h #92
Conversation
…ailable false in renter
lib/renter.js
Outdated
@@ -650,6 +661,8 @@ Renter.prototype._publishContract = function(contacts, contract, callback) { | |||
|
|||
this._logger.warn('Error publishing contract to node: %j, reason: %s', | |||
contact, err.message); | |||
|
|||
seenInLastDay(contactInst); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't be saved/persisted. This is modifying the instance of Contact
from storj-lib, and not the database model.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The instance that needs to be modified is the mongoose model that's return from a database query, which can be done here: https://github.com/nat-ventura/complex/blob/8834c59111fb1f40b40f5384d4cf363ce56e7f93/lib/renter.js#L585-L606
lib/renter.js
Outdated
// Changes spaceAvailable to false if contacts not seen in 24 hours | ||
// so they stop receiving ALLOC messages | ||
if (contact.lastSeen < new Date(Date.now() - 864e5)) { | ||
contact.update({_id: nodeID}, {$set: {spaceAvailable: false}}, (err) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The contact is already being saved on line 610 below this in the function, see https://github.com/nat-ventura/complex/blob/5531afedb2d119027defbe8129c8c0ddd6b22962/lib/renter.js#L610 there isn't a need to call update here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, since the save is being called on recordResponseTime(responseTime)
I just didn't want to overlap/overwrite with anything being saved there. So I should just call set
inside the save function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should just be able to do contact.spaceAvailable = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The mongoose model save
function will make the corresponding mongodb query in one call.
Tested! Looks good to me. |
When there is a failed ALLOC message, checks to see if farmer has been seen in last 24 hours-- if not, sets farmer's spaceAvailable to false.
Closes storj-archived/bridge#557