-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bitswap 1.1.0 and bitswap 1.0.0 using CID #76
Changes from 1 commit
4384208
b15fb89
effdbe2
ae95bbe
84abea9
99d64dd
cebd4b2
3189db6
8758da6
fd60a9c
e7835cb
de99976
8e3b7a7
d15910d
c17f410
89d922e
65dbd28
a8da40a
0dc3b60
32e8997
beff8d1
3dc3493
e892863
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
'use strict' | ||
|
||
const mh = require('multihashes') | ||
|
||
const Entry = require('./entry') | ||
|
||
class Wantlist { | ||
|
@@ -13,33 +11,39 @@ class Wantlist { | |
return this.set.size | ||
} | ||
|
||
add (key, priority) { | ||
const e = this.set.get(mh.toB58String(key)) | ||
add (cid, priority) { | ||
const cidStr = cid.toBaseEncodedString() | ||
const entry = this.set.get(cidStr) | ||
|
||
if (e) { | ||
e.inc() | ||
e.priority = priority | ||
if (entry) { | ||
entry.inc() | ||
entry.priority = priority | ||
} else { | ||
this.set.set(mh.toB58String(key), new Entry(key, priority)) | ||
this.set.set(cidStr, new Entry(cid, priority)) | ||
} | ||
} | ||
|
||
remove (key) { | ||
const e = this.set.get(mh.toB58String(key)) | ||
remove (cid) { | ||
const cidStr = cid.toBaseEncodedString() | ||
const entry = this.set.get(cidStr) | ||
|
||
if (!e) return | ||
if (!entry) { | ||
return | ||
} | ||
|
||
e.dec() | ||
entry.dec() | ||
|
||
// only delete when no refs are held | ||
if (e.hasRefs()) return | ||
if (entry.hasRefs()) { | ||
return | ||
} | ||
|
||
this.set.delete(mh.toB58String(key)) | ||
this.set.delete(cidStr) | ||
} | ||
|
||
removeForce (key) { | ||
if (this.set.has(key)) { | ||
this.set.delete(key) | ||
removeForce (cidStr) { | ||
if (this.set.has(cidStr)) { | ||
this.set.delete(cidStr) | ||
} | ||
} | ||
|
||
|
@@ -51,8 +55,9 @@ class Wantlist { | |
return new Map(Array.from(this.set.entries()).sort()) | ||
} | ||
|
||
contains (key) { | ||
return this.set.get(mh.toB58String(key)) | ||
contains (cid) { | ||
const cidStr = cid.toBaseEncodedString() | ||
return !!this.set.get(cidStr) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will break behaviour in other places, I've used this as a shortcut to avoid double lookups. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, you want it to continue returning the value? ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm okay with refactoring it so that it's not needed anymore, but there are places where changing this breaks things, that's all I wanted to point out. |
||
} | ||
} | ||
|
||
|
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 is not good, you shouldn't use
||
if the input is a number.