<commit_before>//
//  storage.h
//  libjl777
//
//  Created by jl777 on 10/19/14.
//  Copyright (c) 2014 jl777. MIT license
//

#ifndef libjl777_storage_h
#define libjl777_storage_h

#include "db.h"

#define MAX_KADEMLIA_STORAGE (1024L * 1024L * 1024L)
#define PUBLIC_DATA 0
#define PRIVATE_DATA 1

struct kademlia_storage
{
    uint64_t modified,keyhash;
    char key[MAX_NXTTXID_LEN];
    uint32_t datalen,laststored,lastaccess,createtime;
    unsigned char data[];
};
long Total_stored,Storage_maxitems[2];
DB_ENV *Storage;
DB *Public_dbp,*Private_dbp;

union _storage_type { uint64_t destbits; int32_t selector; };
struct storage_queue_entry { struct kademlia_storage *sp; union _storage_type U; };

int32_t init_storage()
{
    int ret;
    ensure_directory("storage");
    if ( 0 )
    {
        if ( (ret = db_env_create(&Storage, 0)) != 0 )
        {
            fprintf(stderr,"Error creating environment handle: %s\n",db_strerror(ret));
            return(-1);
        }
        if ( (ret= Storage->open(Storage,"storage",DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN,0)) != 0 )
        {
            printf("error.%d opening Storage environment\n",ret);
            exit(ret);
        }
    }
    if ( (ret= db_create(&Public_dbp,NULL,0)) != 0 )
    {
        printf("error.%d creating Public_dbp database\n",ret);
        return(ret);
    }
    if ( (ret= db_create(&Private_dbp,NULL,0)) != 0 )
    {
        printf("error.%d creating Private_dbp database\n",ret);
        return(ret);
    }
    if ( (ret= Public_dbp->open(Public_dbp,NULL,"public.db",NULL,DB_HASH,DB_CREATE | 0*DB_AUTO_COMMIT,0)) != 0 )
    {
        printf("error.%d opening Public_dbp database\n",ret);
        return(ret);
    }
    if ( (ret= Private_dbp->open(Private_dbp,NULL,"private.db",NULL,DB_HASH,DB_CREATE | 0*DB_AUTO_COMMIT,0)) != 0 )
    {
        printf("error.%d opening Private_dbp database\n",ret);
        return(ret);
    }
    return(0);
}<commit_msg>setdir<commit_after>//
//  storage.h
//  libjl777
//
//  Created by jl777 on 10/19/14.
//  Copyright (c) 2014 jl777. MIT license
//

#ifndef libjl777_storage_h
#define libjl777_storage_h

#include "db.h"

#define MAX_KADEMLIA_STORAGE (1024L * 1024L * 1024L)
#define PUBLIC_DATA 0
#define PRIVATE_DATA 1

struct kademlia_storage
{
    uint64_t modified,keyhash;
    char key[MAX_NXTTXID_LEN];
    uint32_t datalen,laststored,lastaccess,createtime;
    unsigned char data[];
};
long Total_stored,Storage_maxitems[2];
DB_ENV *Storage;
DB *Public_dbp,*Private_dbp;

union _storage_type { uint64_t destbits; int32_t selector; };
struct storage_queue_entry { struct kademlia_storage *sp; union _storage_type U; };

int32_t init_storage()
{
    int ret;
    ensure_directory("storage");
    if ( 0 )
    {
        if ( (ret = db_env_create(&Storage, 0)) != 0 )
        {
            fprintf(stderr,"Error creating environment handle: %s\n",db_strerror(ret));
            return(-1);
        }
        if ( (ret= Storage->open(Storage,"storage",DB_CREATE|DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN,0)) != 0 )
        {
            printf("error.%d opening Storage environment\n",ret);
            exit(ret);
        }
    }
    if ( (ret= db_create(&Public_dbp,NULL,0)) != 0 )
    {
        printf("error.%d creating Public_dbp database\n",ret);
        return(ret);
    }
    if ( (ret= db_create(&Private_dbp,NULL,0)) != 0 )
    {
        printf("error.%d creating Private_dbp database\n",ret);
        return(ret);
    }
  	(void)Public_dbp->set_create_dir(Public_dbp,"storage");
	(void)Private_dbp->set_create_dir(Private_dbp,"storage");
    if ( (ret= Public_dbp->open(Public_dbp,NULL,"public.db",NULL,DB_HASH,DB_CREATE | 0*DB_AUTO_COMMIT,0)) != 0 )
    {
        printf("error.%d opening Public_dbp database\n",ret);
        return(ret);
    }
    if ( (ret= Private_dbp->open(Private_dbp,NULL,"private.db",NULL,DB_HASH,DB_CREATE | 0*DB_AUTO_COMMIT,0)) != 0 )
    {
        printf("error.%d opening Private_dbp database\n",ret);
        return(ret);
    }
    return(0);
}
{'fraction_non_alphanumeric': 0.1419035846724351, 'fraction_numerical': 0.03312731767614339, 'mean_word_length': 3.218978102189781, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2836441', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1479, 'n_words': 258}