Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

sets spaceAvailable false if ALLOCs fail and contact not seen in 24h #92

Merged
merged 7 commits into from
Mar 2, 2018

Conversation

navillasa
Copy link
Contributor

@navillasa navillasa commented Feb 26, 2018

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

@navillasa navillasa changed the title WIP calls recordLastSeen() in landlord fn _recordSuccessTime WIP calls recordLastSeen() in the Landlord function recordSuccessTime Feb 26, 2018
@navillasa navillasa changed the title WIP calls recordLastSeen() in the Landlord function recordSuccessTime WIP sets spaceAvailable false if ALLOCs fail and contact not seen in 24h Feb 28, 2018
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);
Copy link
Contributor

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.

Copy link
Contributor

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) => {
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

@braydonf braydonf Mar 1, 2018

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.

@braydonf
Copy link
Contributor

braydonf commented Mar 1, 2018

Tested! Looks good to me.

@navillasa navillasa changed the title WIP sets spaceAvailable false if ALLOCs fail and contact not seen in 24h sets spaceAvailable false if ALLOCs fail and contact not seen in 24h Mar 1, 2018
@braydonf braydonf merged commit 2214a87 into storj-archived:master Mar 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants