@cryptotaxi247 / kubo / commits / d0e012342

Remove now unused code

License: MIT Signed-off-by: Jeromy <why@ipfs.io>

Jeromy committed Sep 18, 2016 at 19:49 UTC d0e012342628dc9475e466cd88d70ded06c5791e
4 files changed -238
blocks/key/key.go deleted
-86
@@ -1,86 +0,0 @@
1 -package key
2 -
3 -import (
4 - "encoding/json"
5 - "fmt"
6 -
7 - b58 "gx/ipfs/QmT8rehPR3F6bmwL6zjUN8XpiDBFFpMP2myPdC6ApsWfJf/go-base58"
8 - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
9 - base32 "gx/ipfs/Qmb1DA2A9LS2wR4FFweB4uEDomFsdmnw1VLawLE1yQzudj/base32"
10 - ds "gx/ipfs/QmbzuUusHqaLLoNTDEVLcSF6vZDHZDLPC7p4bztRvvkXxU/go-datastore"
11 -)
12 -
13 -// Key is a string representation of multihash for use with maps.
14 -type Key string
15 -
16 -// String is utililty function for printing out keys as strings (Pretty).
17 -func (k Key) String() string {
18 - return k.B58String()
19 -}
20 -
21 -func (k Key) ToMultihash() mh.Multihash {
22 - return mh.Multihash(k)
23 -}
24 -
25 -// B58String returns Key in a b58 encoded string
26 -func (k Key) B58String() string {
27 - return B58KeyEncode(k)
28 -}
29 -
30 -// B58KeyDecode returns Key from a b58 encoded string
31 -func B58KeyDecode(s string) Key {
32 - return Key(string(b58.Decode(s)))
33 -}
34 -
35 -// B58KeyEncode returns Key in a b58 encoded string
36 -func B58KeyEncode(k Key) string {
37 - return b58.Encode([]byte(k))
38 -}
39 -
40 -// DsKey returns a Datastore key
41 -func (k Key) DsKey() ds.Key {
42 - return ds.NewKey(base32.RawStdEncoding.EncodeToString([]byte(k)))
43 -}
44 -
45 -// UnmarshalJSON returns a JSON-encoded Key (string)
46 -func (k *Key) UnmarshalJSON(mk []byte) error {
47 - var s string
48 - err := json.Unmarshal(mk, &s)
49 - if err != nil {
50 - return err
51 - }
52 -
53 - *k = Key(string(b58.Decode(s)))
54 - if len(*k) == 0 && len(s) > 2 { // if b58.Decode fails, k == ""
55 - return fmt.Errorf("Key.UnmarshalJSON: invalid b58 string: %v", mk)
56 - }
57 - return nil
58 -}
59 -
60 -// MarshalJSON returns a JSON-encoded Key (string)
61 -func (k *Key) MarshalJSON() ([]byte, error) {
62 - return json.Marshal(b58.Encode([]byte(*k)))
63 -}
64 -
65 -func (k *Key) Loggable() map[string]interface{} {
66 - return map[string]interface{}{
67 - "key": k.String(),
68 - }
69 -}
70 -
71 -// KeyFromDsKey returns a Datastore key
72 -func KeyFromDsKey(dsk ds.Key) (Key, error) {
73 - dec, err := base32.RawStdEncoding.DecodeString(dsk.String()[1:])
74 - if err != nil {
75 - return "", err
76 - }
77 -
78 - return Key(dec), nil
79 -}
80 -
81 -// KeySlice is used for sorting Keys
82 -type KeySlice []Key
83 -
84 -func (es KeySlice) Len() int { return len(es) }
85 -func (es KeySlice) Swap(i, j int) { es[i], es[j] = es[j], es[i] }
86 -func (es KeySlice) Less(i, j int) bool { return es[i] < es[j] }
blocks/key/key_set.go deleted
-39
@@ -1,39 +0,0 @@
1 -package key
2 -
3 -type KeySet interface {
4 - Add(Key)
5 - Has(Key) bool
6 - Remove(Key)
7 - Keys() []Key
8 -}
9 -
10 -type keySet struct {
11 - keys map[Key]struct{}
12 -}
13 -
14 -func NewKeySet() KeySet {
15 - return &keySet{make(map[Key]struct{})}
16 -}
17 -
18 -func (gcs *keySet) Add(k Key) {
19 - gcs.keys[k] = struct{}{}
20 -}
21 -
22 -func (gcs *keySet) Has(k Key) bool {
23 - _, has := gcs.keys[k]
24 - return has
25 -}
26 -
27 -func (ks *keySet) Keys() []Key {
28 - var out []Key
29 - for k, _ := range ks.keys {
30 - out = append(out, k)
31 - }
32 - return out
33 -}
34 -
35 -func (ks *keySet) Remove(k Key) {
36 - delete(ks.keys, k)
37 -}
38 -
39 -// TODO: implement disk-backed keyset for working with massive DAGs
blocks/key/key_test.go deleted
-28
@@ -1,28 +0,0 @@
1 -package key
2 -
3 -import (
4 - "bytes"
5 - "testing"
6 -
7 - mh "gx/ipfs/QmYf7ng2hG5XBtJA3tN34DQ2GUN5HNksEw1rLDkmr6vGku/go-multihash"
8 -)
9 -
10 -func TestKey(t *testing.T) {
11 -
12 - h1, err := mh.Sum([]byte("beep boop"), mh.SHA2_256, -1)
13 - if err != nil {
14 - t.Error(err)
15 - }
16 -
17 - k1 := Key(h1)
18 - h2 := mh.Multihash(k1)
19 - k2 := Key(h2)
20 -
21 - if !bytes.Equal(h1, h2) {
22 - t.Error("Multihashes not equal.")
23 - }
24 -
25 - if k1 != k2 {
26 - t.Error("Keys not equal.")
27 - }
28 -}
notifications/query.go deleted
-85
@@ -1,85 +0,0 @@
1 -package notifications
2 -
3 -import (
4 - "encoding/json"
5 -
6 - peer "gx/ipfs/QmWXjJo15p4pzT7cayEwZi2sWgJqLnGDof6ZGMh9xBgU1p/go-libp2p-peer"
7 - context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
8 - pstore "gx/ipfs/QmdMfSLMDBDYhtc4oF3NYGCZr5dy4wQb6Ji26N4D4mdxa2/go-libp2p-peerstore"
9 -)
10 -
11 -const RoutingQueryKey = "RoutingQueryEvent"
12 -
13 -type QueryEventType int
14 -
15 -const (
16 - SendingQuery QueryEventType = iota
17 - PeerResponse
18 - FinalPeer
19 - QueryError
20 - Provider
21 - Value
22 - AddingPeer
23 - DialingPeer
24 -)
25 -
26 -type QueryEvent struct {
27 - ID peer.ID
28 - Type QueryEventType
29 - Responses []*pstore.PeerInfo
30 - Extra string
31 -}
32 -
33 -func RegisterForQueryEvents(ctx context.Context, ch chan<- *QueryEvent) context.Context {
34 - return context.WithValue(ctx, RoutingQueryKey, ch)
35 -}
36 -
37 -func PublishQueryEvent(ctx context.Context, ev *QueryEvent) {
38 - ich := ctx.Value(RoutingQueryKey)
39 - if ich == nil {
40 - return
41 - }
42 -
43 - ch, ok := ich.(chan<- *QueryEvent)
44 - if !ok {
45 - return
46 - }
47 -
48 - select {
49 - case ch <- ev:
50 - case <-ctx.Done():
51 - }
52 -}
53 -
54 -func (qe *QueryEvent) MarshalJSON() ([]byte, error) {
55 - out := make(map[string]interface{})
56 - out["ID"] = peer.IDB58Encode(qe.ID)
57 - out["Type"] = int(qe.Type)
58 - out["Responses"] = qe.Responses
59 - out["Extra"] = qe.Extra
60 - return json.Marshal(out)
61 -}
62 -
63 -func (qe *QueryEvent) UnmarshalJSON(b []byte) error {
64 - temp := struct {
65 - ID string
66 - Type int
67 - Responses []*pstore.PeerInfo
68 - Extra string
69 - }{}
70 - err := json.Unmarshal(b, &temp)
71 - if err != nil {
72 - return err
73 - }
74 - if len(temp.ID) > 0 {
75 - pid, err := peer.IDB58Decode(temp.ID)
76 - if err != nil {
77 - return err
78 - }
79 - qe.ID = pid
80 - }
81 - qe.Type = QueryEventType(temp.Type)
82 - qe.Responses = temp.Responses
83 - qe.Extra = temp.Extra
84 - return nil
85 -}