Initial implementation of pin/pin

This commit is contained in:
Jose Marcial Vieira Bisneto 2016-12-30 01:18:03 -03:00
parent d9774095d3
commit ef380f2a69
7 changed files with 101 additions and 2 deletions

View file

@ -12,6 +12,7 @@ all:
cd merkledag; make all;
cd multibase; make all;
cd os; make all;
cd pin; make all;
cd repo; make all;
cd flatfs; make all;
cd datastore; make all;
@ -30,6 +31,7 @@ clean:
cd merkledag; make clean;
cd multibase; make clean;
cd os; make clean;
cd pin; make clean;
cd repo; make clean;
cd flatfs; make clean;
cd datastore; make clean;

32
include/ipfs/pin/pin.h Normal file
View file

@ -0,0 +1,32 @@
#ifndef IPFS_PIN_H
#define IPFS_PIN_H
#include "ipfs/util/errs.h"
#ifdef IPFS_PIN_C
const char *ipfs_pin_linkmap[] = {
"recursive",
"direct",
"indirect",
"internal",
"not pinned",
"any",
"all"
};
#else // IPFS_PIN_C
extern const char *ipfs_pin_map[];
#endif // IPFS_PIN_C
enum {
Recursive = 0,
Direct,
Indirect,
Internal,
NotPinned,
Any,
All
};
typedef int PinMode;
int ipfs_pin_init ();
#endif // IPFS_PIN_H

View file

@ -26,6 +26,7 @@
ErrResolveLimit,
ErrInvalidSignature,
ErrInvalidSignatureFmt,
ErrNoRecord
ErrNoRecord,
ErrCidDecodeFailed
} ErrsIdx;
#endif // IPFS_ERRS_H

View file

@ -9,6 +9,7 @@ OBJS = main.o \
../commands/argument.o ../commands/command_option.o ../commands/command.o ../commands/cli/parse.o \
../core/builder.o \
../datastore/ds_helper.o \
../datastore/key.o \
../dnslink/dnslink.o \
../flatfs/flatfs.o \
../importer/importer.o ../importer/exporter.o ../importer/resolver.o \
@ -17,6 +18,7 @@ OBJS = main.o \
../multibase/multibase.o \
../namesys/isdomain.o \
../os/utils.o \
../pin/pin.o \
../repo/init.o \
../repo/fsrepo/fs_repo.o ../repo/fsrepo/jsmn.o ../repo/fsrepo/lmdb_datastore.o \
../repo/config/config.o ../repo/config/identity.o \

18
pin/Makefile Normal file
View file

@ -0,0 +1,18 @@
CC = gcc
CFLAGS = -O0 -I../include -I../../c-libp2p/include -I../../c-multihash/include -I../../c-multiaddr/include -I../../c-protobuf -Wall
ifdef DEBUG
CFLAGS += -g3
endif
LFLAGS =
DEPS =
OBJS = pin.o
%.o: %.c $(DEPS)
$(CC) -c -o $@ $< $(CFLAGS)
all: $(OBJS)
clean:
rm -f *.o

43
pin/pin.c Normal file
View file

@ -0,0 +1,43 @@
#include <stdlib.h>
#include <string.h>
#define IPFS_PIN_C
#include "ipfs/pin/pin.h"
#include "ipfs/cid/cid.h"
#include "ipfs/datastore/key.h"
#include "ipfs/util/errs.h"
// package pin implements structures and methods to keep track of
// which objects a user wants to keep stored locally.
#define PIN_DATASTOREKEY_SIZE 100
char *pinDatastoreKey = NULL;
size_t pinDatastoreKeySize = 0;
struct Cid *emptyKey = NULL;
int ipfs_pin_init ()
{
int err;
unsigned char *empty_hash = (unsigned char*) "QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n";
if (!pinDatastoreKey) { // initialize just one time.
pinDatastoreKey = malloc(PIN_DATASTOREKEY_SIZE);
if (!pinDatastoreKey) {
return ErrAllocFailed;
}
err = ipfs_datastore_key_new("/local/pins", pinDatastoreKey, PIN_DATASTOREKEY_SIZE, &pinDatastoreKeySize);
if (err) {
free (pinDatastoreKey);
pinDatastoreKey = NULL;
return err;
}
if (!ipfs_cid_protobuf_decode(empty_hash, strlen ((char*)empty_hash), &emptyKey)) {
return ErrCidDecodeFailed;
}
}
return 0;
}

View file

@ -28,5 +28,6 @@ char *Err[] = {
"resolve depth exceeded",
NULL,
"Invalid value. Not signed by PrivateKey corresponding to %s",
"no usable records in given set"
"no usable records in given set",
"failed to decode empty key constant"
};