diff --git a/bittorrent_jni/AUTHORS b/bittorrent_jni/AUTHORS deleted file mode 100644 index e69de29..0000000 diff --git a/bittorrent_jni/COPYING b/bittorrent_jni/COPYING deleted file mode 100644 index e69de29..0000000 diff --git a/bittorrent_jni/ChangeLog b/bittorrent_jni/ChangeLog deleted file mode 100644 index e69de29..0000000 diff --git a/bittorrent_jni/INSTALL b/bittorrent_jni/INSTALL deleted file mode 100644 index 7d1c323..0000000 --- a/bittorrent_jni/INSTALL +++ /dev/null @@ -1,365 +0,0 @@ -Installation Instructions -************************* - -Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, -2006, 2007, 2008, 2009 Free Software Foundation, Inc. - - Copying and distribution of this file, with or without modification, -are permitted in any medium without royalty provided the copyright -notice and this notice are preserved. This file is offered as-is, -without warranty of any kind. - -Basic Installation -================== - - Briefly, the shell commands `./configure; make; make install' should -configure, build, and install this package. The following -more-detailed instructions are generic; see the `README' file for -instructions specific to this package. Some packages provide this -`INSTALL' file but do not implement all of the features documented -below. The lack of an optional feature in a given package is not -necessarily a bug. More recommendations for GNU packages can be found -in *note Makefile Conventions: (standards)Makefile Conventions. - - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory of the package. -It may also create one or more `.h' files containing system-dependent -definitions. Finally, it creates a shell script `config.status' that -you can run in the future to recreate the current configuration, and a -file `config.log' containing compiler output (useful mainly for -debugging `configure'). - - It can also use an optional file (typically called `config.cache' -and enabled with `--cache-file=config.cache' or simply `-C') that saves -the results of its tests to speed up reconfiguring. Caching is -disabled by default to prevent problems with accidental use of stale -cache files. - - If you need to do unusual things to compile the package, please try -to figure out how `configure' could check whether to do them, and mail -diffs or instructions to the address given in the `README' so they can -be considered for the next release. If you are using the cache, and at -some point `config.cache' contains results you don't want to keep, you -may remove or edit it. - - The file `configure.ac' (or `configure.in') is used to create -`configure' by a program called `autoconf'. You need `configure.ac' if -you want to change it or regenerate `configure' using a newer version -of `autoconf'. - - The simplest way to compile this package is: - - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. - - Running `configure' might take a while. While running, it prints - some messages telling which features it is checking for. - - 2. Type `make' to compile the package. - - 3. Optionally, type `make check' to run any self-tests that come with - the package, generally using the just-built uninstalled binaries. - - 4. Type `make install' to install the programs and any data files and - documentation. When installing into a prefix owned by root, it is - recommended that the package be configured and built as a regular - user, and only the `make install' phase executed with root - privileges. - - 5. Optionally, type `make installcheck' to repeat any self-tests, but - this time using the binaries in their final installed location. - This target does not install anything. Running this target as a - regular user, particularly if the prior `make install' required - root privileges, verifies that the installation completed - correctly. - - 6. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. There is - also a `make maintainer-clean' target, but that is intended mainly - for the package's developers. If you use it, you may have to get - all sorts of other programs in order to regenerate files that came - with the distribution. - - 7. Often, you can also type `make uninstall' to remove the installed - files again. In practice, not all packages have tested that - uninstallation works correctly, even though it is required by the - GNU Coding Standards. - - 8. Some packages, particularly those that use Automake, provide `make - distcheck', which can by used by developers to test that all other - targets like `make install' and `make uninstall' work correctly. - This target is generally not run by end users. - -Compilers and Options -===================== - - Some systems require unusual options for compilation or linking that -the `configure' script does not know about. Run `./configure --help' -for details on some of the pertinent environment variables. - - You can give `configure' initial values for configuration parameters -by setting variables in the command line or in the environment. Here -is an example: - - ./configure CC=c99 CFLAGS=-g LIBS=-lposix - - *Note Defining Variables::, for more details. - -Compiling For Multiple Architectures -==================================== - - You can compile the package for more than one kind of computer at the -same time, by placing the object files for each architecture in their -own directory. To do this, you can use GNU `make'. `cd' to the -directory where you want the object files and executables to go and run -the `configure' script. `configure' automatically checks for the -source code in the directory that `configure' is in and in `..'. This -is known as a "VPATH" build. - - With a non-GNU `make', it is safer to compile the package for one -architecture at a time in the source code directory. After you have -installed the package for one architecture, use `make distclean' before -reconfiguring for another architecture. - - On MacOS X 10.5 and later systems, you can create libraries and -executables that work on multiple system types--known as "fat" or -"universal" binaries--by specifying multiple `-arch' options to the -compiler but only a single `-arch' option to the preprocessor. Like -this: - - ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ - CPP="gcc -E" CXXCPP="g++ -E" - - This is not guaranteed to produce working output in all cases, you -may have to build one architecture at a time and combine the results -using the `lipo' tool if you have problems. - -Installation Names -================== - - By default, `make install' installs the package's commands under -`/usr/local/bin', include files under `/usr/local/include', etc. You -can specify an installation prefix other than `/usr/local' by giving -`configure' the option `--prefix=PREFIX', where PREFIX must be an -absolute file name. - - You can specify separate installation prefixes for -architecture-specific files and architecture-independent files. If you -pass the option `--exec-prefix=PREFIX' to `configure', the package uses -PREFIX as the prefix for installing programs and libraries. -Documentation and other data files still use the regular prefix. - - In addition, if you use an unusual directory layout you can give -options like `--bindir=DIR' to specify different values for particular -kinds of files. Run `configure --help' for a list of the directories -you can set and what kinds of files go in them. In general, the -default for these options is expressed in terms of `${prefix}', so that -specifying just `--prefix' will affect all of the other directory -specifications that were not explicitly provided. - - The most portable way to affect installation locations is to pass the -correct locations to `configure'; however, many packages provide one or -both of the following shortcuts of passing variable assignments to the -`make install' command line to change installation locations without -having to reconfigure or recompile. - - The first method involves providing an override variable for each -affected directory. For example, `make install -prefix=/alternate/directory' will choose an alternate location for all -directory configuration variables that were expressed in terms of -`${prefix}'. Any directories that were specified during `configure', -but not in terms of `${prefix}', must each be overridden at install -time for the entire installation to be relocated. The approach of -makefile variable overrides for each directory variable is required by -the GNU Coding Standards, and ideally causes no recompilation. -However, some platforms have known limitations with the semantics of -shared libraries that end up requiring recompilation when using this -method, particularly noticeable in packages that use GNU Libtool. - - The second method involves providing the `DESTDIR' variable. For -example, `make install DESTDIR=/alternate/directory' will prepend -`/alternate/directory' before all installation names. The approach of -`DESTDIR' overrides is not required by the GNU Coding Standards, and -does not work on platforms that have drive letters. On the other hand, -it does better at avoiding recompilation issues, and works well even -when some directory options were not specified in terms of `${prefix}' -at `configure' time. - -Optional Features -================= - - If the package supports it, you can cause programs to be installed -with an extra prefix or suffix on their names by giving `configure' the -option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. - - Some packages pay attention to `--enable-FEATURE' options to -`configure', where FEATURE indicates an optional part of the package. -They may also pay attention to `--with-PACKAGE' options, where PACKAGE -is something like `gnu-as' or `x' (for the X Window System). The -`README' should mention any `--enable-' and `--with-' options that the -package recognizes. - - For packages that use the X Window System, `configure' can usually -find the X include and library files automatically, but if it doesn't, -you can use the `configure' options `--x-includes=DIR' and -`--x-libraries=DIR' to specify their locations. - - Some packages offer the ability to configure how verbose the -execution of `make' will be. For these packages, running `./configure ---enable-silent-rules' sets the default to minimal output, which can be -overridden with `make V=1'; while running `./configure ---disable-silent-rules' sets the default to verbose, which can be -overridden with `make V=0'. - -Particular systems -================== - - On HP-UX, the default C compiler is not ANSI C compatible. If GNU -CC is not installed, it is recommended to use the following options in -order to use an ANSI C compiler: - - ./configure CC="cc -Ae -D_XOPEN_SOURCE=500" - -and if that doesn't work, install pre-built binaries of GCC for HP-UX. - - On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot -parse its `' header file. The option `-nodtk' can be used as -a workaround. If GNU CC is not installed, it is therefore recommended -to try - - ./configure CC="cc" - -and if that doesn't work, try - - ./configure CC="cc -nodtk" - - On Solaris, don't put `/usr/ucb' early in your `PATH'. This -directory contains several dysfunctional programs; working variants of -these programs are available in `/usr/bin'. So, if you need `/usr/ucb' -in your `PATH', put it _after_ `/usr/bin'. - - On Haiku, software installed for all users goes in `/boot/common', -not `/usr/local'. It is recommended to use the following options: - - ./configure --prefix=/boot/common - -Specifying the System Type -========================== - - There may be some features `configure' cannot figure out -automatically, but needs to determine by the type of machine the package -will run on. Usually, assuming the package is built to be run on the -_same_ architectures, `configure' can figure that out, but if it prints -a message saying it cannot guess the machine type, give it the -`--build=TYPE' option. TYPE can either be a short name for the system -type, such as `sun4', or a canonical name which has the form: - - CPU-COMPANY-SYSTEM - -where SYSTEM can have one of these forms: - - OS - KERNEL-OS - - See the file `config.sub' for the possible values of each field. If -`config.sub' isn't included in this package, then this package doesn't -need to know the machine type. - - If you are _building_ compiler tools for cross-compiling, you should -use the option `--target=TYPE' to select the type of system they will -produce code for. - - If you want to _use_ a cross compiler, that generates code for a -platform different from the build platform, you should specify the -"host" platform (i.e., that on which the generated programs will -eventually be run) with `--host=TYPE'. - -Sharing Defaults -================ - - If you want to set default values for `configure' scripts to share, -you can create a site shell script called `config.site' that gives -default values for variables like `CC', `cache_file', and `prefix'. -`configure' looks for `PREFIX/share/config.site' if it exists, then -`PREFIX/etc/config.site' if it exists. Or, you can set the -`CONFIG_SITE' environment variable to the location of the site script. -A warning: not all `configure' scripts look for a site script. - -Defining Variables -================== - - Variables not defined in a site shell script can be set in the -environment passed to `configure'. However, some packages may run -configure again during the build, and the customized values of these -variables may be lost. In order to avoid this problem, you should set -them in the `configure' command line, using `VAR=value'. For example: - - ./configure CC=/usr/local2/bin/gcc - -causes the specified `gcc' to be used as the C compiler (unless it is -overridden in the site shell script). - -Unfortunately, this technique does not work for `CONFIG_SHELL' due to -an Autoconf bug. Until the bug is fixed you can use this workaround: - - CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash - -`configure' Invocation -====================== - - `configure' recognizes the following options to control how it -operates. - -`--help' -`-h' - Print a summary of all of the options to `configure', and exit. - -`--help=short' -`--help=recursive' - Print a summary of the options unique to this package's - `configure', and exit. The `short' variant lists options used - only in the top level, while the `recursive' variant lists options - also present in any nested packages. - -`--version' -`-V' - Print the version of Autoconf used to generate the `configure' - script, and exit. - -`--cache-file=FILE' - Enable the cache: use and save the results of the tests in FILE, - traditionally `config.cache'. FILE defaults to `/dev/null' to - disable caching. - -`--config-cache' -`-C' - Alias for `--cache-file=config.cache'. - -`--quiet' -`--silent' -`-q' - Do not print messages saying which checks are being made. To - suppress all normal output, redirect it to `/dev/null' (any error - messages will still be shown). - -`--srcdir=DIR' - Look for the package's source code in directory DIR. Usually - `configure' can determine that directory automatically. - -`--prefix=DIR' - Use DIR as the installation prefix. *note Installation Names:: - for more details, including other options available for fine-tuning - the installation locations. - -`--no-create' -`-n' - Run the configure checks, but stop before creating any output - files. - -`configure' also accepts some other, not widely useful, options. Run -`configure --help' for more details. - diff --git a/bittorrent_jni/Makefile.am b/bittorrent_jni/Makefile.am deleted file mode 100644 index 0251ee7..0000000 --- a/bittorrent_jni/Makefile.am +++ /dev/null @@ -1,11 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 - -SUBDIRS = \ - third-party \ - libtransmission \ - cli - -DISTCLEANFILES = \ - intltool-extract \ - intltool-merge \ - intltool-update diff --git a/bittorrent_jni/NEWS b/bittorrent_jni/NEWS deleted file mode 100644 index e69de29..0000000 diff --git a/bittorrent_jni/README b/bittorrent_jni/README deleted file mode 100644 index d5e4136..0000000 --- a/bittorrent_jni/README +++ /dev/null @@ -1 +0,0 @@ -Follow the directions in INSTALL. diff --git a/bittorrent_jni/clean_build.sh b/bittorrent_jni/clean_build.sh deleted file mode 100755 index b32d4aa..0000000 --- a/bittorrent_jni/clean_build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -make clean - -rm -rf external libtransmission third-party m4 \ - autom4te.cache aclocal.m4 install-sh ltmain.sh missing \ - configure config.guess config.sub config.log config.status depcomp \ - libtool cli/.deps cli/Makefile.in cli/Makefile Makefile.in Makefile diff --git a/bittorrent_jni/cli/Makefile.am b/bittorrent_jni/cli/Makefile.am deleted file mode 100644 index f6aa6c0..0000000 --- a/bittorrent_jni/cli/Makefile.am +++ /dev/null @@ -1,48 +0,0 @@ -AM_CPPFLAGS = \ - -I@top_srcdir@ \ - -D__TRANSMISSION__ - -AM_CFLAGS = \ - @LIBEVENT_CFLAGS@ \ - @LIBSQLITE3_CFLAGS@ \ - @OPENSSL_CFLAGS@ \ - @LIBCURL_CFLAGS@ \ - @ZLIB_CFLAGS@ \ - @JAVA_CFLAGS@ \ - @PTHREAD_CFLAGS@ - -AM_LDFLAGS = \ - @ZLIB_LDFLAGS@ - -bin_PROGRAMS = seeding - -seeding_SOURCES = seeding.c - -seeding_LDADD = \ - $(top_builddir)/libtransmission/libtransmission.la \ - $(top_builddir)/third-party/libnatpmp/libnatpmp.la \ - $(top_builddir)/third-party/miniupnp/libminiupnp.la \ - @DHT_LIBS@ \ - @LIBEVENT_LIBS@ \ - @LIBSQLITE3_LIBS@ \ - @LIBCURL_LIBS@ \ - @OPENSSL_LIBS@ \ - @INTLLIBS@ \ - @ZLIB_LIBS@ \ - @PTHREAD_LIBS@ - -lib_LTLIBRARIES = libbtclient.la - -libbtclient_la_SOURCES = client.c - -libbtclient_la_LIBADD = \ - $(top_builddir)/libtransmission/libtransmission.la \ - $(top_builddir)/third-party/libnatpmp/libnatpmp.la \ - $(top_builddir)/third-party/miniupnp/libminiupnp.la \ - @DHT_LIBS@ \ - @LIBEVENT_LIBS@ \ - @LIBCURL_LIBS@ \ - @OPENSSL_LIBS@ \ - @INTLLIBS@ \ - @ZLIB_LIBS@ \ - @PTHREAD_LIBS@ diff --git a/bittorrent_jni/cli/client.c b/bittorrent_jni/cli/client.c deleted file mode 100644 index c0ea45f..0000000 --- a/bittorrent_jni/cli/client.c +++ /dev/null @@ -1,355 +0,0 @@ -#include "orca_imageproxy_BTDownload.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include /* tr_wait_msec */ -#include -#include /* tr_webRun */ - -/*** -**** -***/ - -#define MEM_K 1024 -#define MEM_K_STR "KiB" -#define MEM_M_STR "MiB" -#define MEM_G_STR "GiB" -#define MEM_T_STR "TiB" - -#define DISK_K 1024 -#define DISK_B_STR "B" -#define DISK_K_STR "KiB" -#define DISK_M_STR "MiB" -#define DISK_G_STR "GiB" -#define DISK_T_STR "TiB" - -#define SPEED_K 1024 -#define SPEED_B_STR "B/s" -#define SPEED_K_STR "KiB/s" -#define SPEED_M_STR "MiB/s" -#define SPEED_G_STR "GiB/s" -#define SPEED_T_STR "TiB/s" - -const char * downloadDir="/download"; -const char * configDir="/settings"; -char * rootfolder=NULL; -static tr_bool waitingOnWeb; -static tr_bool verify = 0; -tr_session * h=NULL; -tr_benc settings; - -static void -onTorrentFileDownloaded( tr_session * session UNUSED, - long response_code UNUSED, - const void * response, - size_t response_byte_count, - void * ctor ) -{ - tr_ctorSetMetainfo( ctor, response, response_byte_count ); - waitingOnWeb = FALSE; -} - -static char* -getResumeFilename( const tr_info *info ) -{ - char * base = tr_metainfoGetBasename( info ); - char * filename = tr_strdup_printf( "%s" TR_PATH_DELIMITER_STR "%s.resume", - tr_getResumeDir( h ), base ); - tr_free( base ); - return filename; -} - -JNIEXPORT void JNICALL Java_orca_imageproxy_BTDownload_initSession - (JNIEnv * env, jobject obj, jstring path) -{ - if(h==NULL) - { - rootfolder=(*env)->GetStringUTFChars(env, path, 0); - char* download_path[strlen(rootfolder)+strlen(downloadDir)]; - char* config_path[strlen(rootfolder)+strlen(configDir)]; - sprintf(download_path, "%s%s", rootfolder, downloadDir); - sprintf(config_path, "%s%s", rootfolder, configDir); - - tr_formatter_mem_init( MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR ); - tr_formatter_size_init( DISK_K,DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR ); - tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR ); - tr_bencInitDict( &settings, 0 ); - tr_sessionLoadSettings( &settings, config_path, "BT" ); - tr_bencDictAddStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, download_path ); - h = tr_sessionInit( "client", config_path, FALSE, &settings ); - } -} - -JNIEXPORT jlong JNICALL Java_orca_imageproxy_BTDownload_getFileLength - (JNIEnv * env, jobject obj, jstring url) -{ - int parse_result; - tr_ctor * ctor; - tr_info setme_info; - const char *torrentPath=(*env)->GetStringUTFChars(env, url, 0); - if(h==NULL) - { - char *errbuffer="the session is not initialized"; - jclass newExcCls=(*env)->FindClass(env,"java/lang/NullPointerException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - return 0; - } - ctor = tr_ctorNew( h ); - tr_ctorSetPaused( ctor, TR_FORCE, FALSE ); - if( !memcmp( torrentPath, "http", 4 ) ) { - tr_webRun( h, torrentPath, NULL, onTorrentFileDownloaded, ctor ); - waitingOnWeb = TRUE; - while( waitingOnWeb ) tr_wait_msec( 1000 ); - } else { - char errbuffer[strlen(torrentPath)+50];//50 for error messages - sprintf( errbuffer, "ERROR: Unrecognized torrent \"%s\".\n", torrentPath ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - return 0; - } - - parse_result = tr_torrentParse( ctor, &setme_info ); - tr_ctorFree( ctor ); - if( parse_result==TR_PARSE_ERR) - { - char errbuffer[strlen(torrentPath)+100];//100 for error messages - sprintf( errbuffer, "Failed opening torrent file '%s'\n", torrentPath ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - return 0; - } - if(setme_info.fileCount!=1) - { - char *errbuffer="one torrent should only contain one image file!"; - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - return 0; - } - int64_t length = setme_info.files[0].length; - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - return length; -} - -JNIEXPORT void JNICALL Java_orca_imageproxy_BTDownload_deleteImageBT - (JNIEnv * env, jobject obj, jstring hash, jstring url) -{ - int parse_result; - tr_ctor * ctor; - tr_info setme_info; - uint8_t * fileContents; - size_t fileLength; - - char *torrentPath=(*env)->GetStringUTFChars(env, url, 0); - char *filename=(char *)(*env)->GetStringUTFChars(env, hash, 0); - - if(h==NULL) - { - char *errbuffer="the session is not initialized"; - jclass newExcCls=(*env)->FindClass(env,"java/lang/NullPointerException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return; - } - ctor = tr_ctorNew( h ); - fileContents = tr_loadFile( torrentPath, &fileLength ); - tr_ctorSetPaused( ctor, TR_FORCE, FALSE ); - if( fileContents != NULL ) { - tr_ctorSetMetainfo( ctor, fileContents, fileLength ); - }else{ - //it haven't been downloaded yet - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return; - } - tr_free( fileContents ); - parse_result = tr_torrentParse( ctor, &setme_info ); - tr_ctorFree( ctor ); - if( parse_result==TR_PARSE_ERR) - { - char errbuffer[strlen(torrentPath)+50];//50 for error messages - sprintf( errbuffer, "Failed opening torrent file `%s'\n", torrentPath ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return; - } - else - { - char downloadedImage[strlen(rootfolder)+strlen(downloadDir)+1+strlen(filename)]; - //downloaded image path includes rootfolder+downloadfolder+seperator+filename - sprintf(downloadedImage, "%s%s/%s", rootfolder, downloadDir, filename); - //delete the image, torrent and resume - unlink(downloadedImage); - char *resumeName=getResumeFilename(&setme_info); - unlink(resumeName); - tr_free(resumeName); - unlink(setme_info.torrent); - } - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); -} - -JNIEXPORT jstring JNICALL Java_orca_imageproxy_BTDownload_btdownloadfromURL - (JNIEnv * env, jobject obj, jstring url, jstring hash) -{ - int error; - tr_ctor * ctor; - tr_torrent * tor = NULL; - int completeFlag=0; - - const char *torrentPath=(*env)->GetStringUTFChars(env, url, 0); - char *filename=(char *)(*env)->GetStringUTFChars(env, hash, 0); - char *originalName=NULL;//store the image file's original name contained in the torrent file - const tr_stat * st; - const char * messageName[] = { NULL, "Tracker gave a warning:", - "Tracker gave an error:", - "Error:" }; - if(h==NULL) - { - char *errbuffer="the session is not initialized"; - jclass newExcCls=(*env)->FindClass(env,"java/lang/NullPointerException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return NULL; - } - - ctor = tr_ctorNew( h ); - tr_ctorSetPaused( ctor, TR_FORCE, FALSE ); - if( !memcmp( torrentPath, "http", 4 ) ) { - tr_webRun( h, torrentPath, NULL, onTorrentFileDownloaded, ctor ); - waitingOnWeb = TRUE; - while( waitingOnWeb ) tr_wait_msec( 1000 ); - } else { - char errbuffer[strlen(torrentPath)+50];//50 for error messages - sprintf( errbuffer, "ERROR: Unrecognized torrent \"%s\".\n", torrentPath ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return NULL; - } - tor = tr_torrentNew( ctor, &error ); - tr_ctorFree( ctor ); - - if( !tor ) - { - char errbuffer[strlen(torrentPath)+50];//50 for error messages - if(error==TR_PARSE_ERR) - sprintf( errbuffer, "Failed opening torrent file '%s'\n", torrentPath ); - else if(error==TR_PARSE_DUPLICATE) - sprintf( errbuffer, "Failed opening torrent file '%s', because it may have been downloading already\n", torrentPath ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return NULL; - } - else - { - tr_torrentSetDirty(tor); - st = tr_torrentStat( tor ); - if( messageName[st->error] ) - { - char errbuffer[strlen(st->errorString)+strlen(messageName[st->error])+10];//10 for additional characters besides error messages - sprintf( errbuffer, "\n%s: %s\n", messageName[st->error], st->errorString ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - tr_torrentFree(tor); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return NULL; - } - if(tor->info.fileCount!=1) - { - char *errbuffer="one torrent should only contain one image file!"; - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - - tr_torrentFree(tor); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return NULL; - } - //store the original name - originalName=tor->info.files[0].name; - //change the name of download file - tor->info.files[0].name=filename; - } - tr_torrentStart( tor ); - if( verify ) - { - verify = 0; - tr_torrentVerify( tor ); - } - st = tr_torrentStat( tor ); - jstring correctHash=NULL; - - do - { - st = tr_torrentStat( tor ); - if( st->activity & TR_STATUS_STOPPED ) - { - char errbuffer[strlen(torrentPath)+50];//50 for error messages - sprintf( errbuffer, "the status of torrent file '%s' is stopped\n", torrentPath ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - break; - } - else if( st->activity & TR_STATUS_SEED ) - { - completeFlag=1; - - int entry_len=strlen(filename)+strlen(torrentPath)+strlen(tor->info.torrent)+2; - //entry_len=length of(hash + '#' + url + '#' + torrentFilePath) - char entry[entry_len]; - sprintf(entry, "%s#%s#%s", filename, torrentPath, tor->info.torrent); - if(originalName!=NULL) - tor->info.files[0].name=originalName; - tr_torrentFree(tor); - jmethodID mid=(*env)->GetMethodID(env, (*env)->GetObjectClass(env,obj), "callbackComplete", "(Ljava/lang/String;)Ljava/lang/String;"); - correctHash=(jstring)(*env)->CallObjectMethod(env, obj, mid, (*env)->NewStringUTF(env, entry)); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return correctHash; - } - if( messageName[st->error] ) - { - char errbuffer[strlen(st->errorString)+strlen(messageName[st->error])+10];//10 for additional characters besides error messages - sprintf( errbuffer, "\n%s: %s\n", messageName[st->error], st->errorString ); - jclass newExcCls=(*env)->FindClass(env,"java/io/IOException"); - (*env)->ThrowNew(env, newExcCls, errbuffer); - break; - } - tr_wait_msec( 200 ); - }while(!completeFlag); - - if(originalName!=NULL) - tor->info.files[0].name=originalName; - tr_torrentFree(tor); - (*env)->ReleaseStringUTFChars(env, url, torrentPath); - (*env)->ReleaseStringUTFChars(env, hash, filename); - return correctHash; -} diff --git a/bittorrent_jni/cli/orca_imageproxy_BTDownload.h b/bittorrent_jni/cli/orca_imageproxy_BTDownload.h deleted file mode 100644 index da77931..0000000 --- a/bittorrent_jni/cli/orca_imageproxy_BTDownload.h +++ /dev/null @@ -1,45 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class orca_imageproxy_BTDownload */ - -#ifndef _Included_orca_imageproxy_BTDownload -#define _Included_orca_imageproxy_BTDownload -#ifdef __cplusplus -extern "C" { -#endif -/* - * Class: orca_imageproxy_BTDownload - * Method: deleteImageBT - * Signature: (Ljava/lang/String;Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_orca_imageproxy_BTDownload_deleteImageBT - (JNIEnv *, jobject, jstring, jstring); - -/* - * Class: orca_imageproxy_BTDownload - * Method: getFileLength - * Signature: (Ljava/lang/String;)Ljava/lang/Long; - */ -JNIEXPORT jlong JNICALL Java_orca_imageproxy_BTDownload_getFileLength - (JNIEnv *, jobject, jstring); - -/* - * Class: orca_imageproxy_BTDownload - * Method: initSession - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_orca_imageproxy_BTDownload_initSession - (JNIEnv *, jobject, jstring); - -/* - * Class: orca_imageproxy_BTDownload - * Method: btdownloadfromURL - * Signature: (Ljava/lang/String;Ljava/lang/String;)V - */ -JNIEXPORT jstring JNICALL Java_orca_imageproxy_BTDownload_btdownloadfromURL - (JNIEnv *, jobject, jstring, jstring); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/bittorrent_jni/cli/seeding.c b/bittorrent_jni/cli/seeding.c deleted file mode 100644 index 28fc56f..0000000 --- a/bittorrent_jni/cli/seeding.c +++ /dev/null @@ -1,252 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include /* tr_wait_msec */ -#include -#include /* tr_webRun */ -#include - -/*** -**** -***/ - -#define MEM_K 1024 -#define MEM_K_STR "KiB" -#define MEM_M_STR "MiB" -#define MEM_G_STR "GiB" -#define MEM_T_STR "TiB" - -#define DISK_K 1024 -#define DISK_B_STR "B" -#define DISK_K_STR "KiB" -#define DISK_M_STR "MiB" -#define DISK_G_STR "GiB" -#define DISK_T_STR "TiB" - -#define SPEED_K 1024 -#define SPEED_B_STR "B/s" -#define SPEED_K_STR "KiB/s" -#define SPEED_M_STR "MiB/s" -#define SPEED_G_STR "GiB/s" -#define SPEED_T_STR "TiB/s" - -char * rootDir=NULL; -char * database=NULL; -char * configDir="/settings"; -char * downloadDir="/download"; -tr_session * h=NULL; -tr_benc settings; -sqlite3 *db = NULL; - -static -char* readProperties(char* ); - -static -void sessionInit(const char* root) -{ - if(h==NULL) - { - char cDir[strlen(root)+strlen(configDir)]; - char dDir[strlen(root)+strlen(downloadDir)]; - sprintf(cDir,"%s%s", root, configDir); - sprintf(dDir, "%s%s", root, downloadDir); - struct stat cDirStat, dDirStat; - int cDirExist=stat(cDir, &cDirStat); - int dDirExist=stat(dDir, &dDirStat); - if(!S_ISDIR(cDirStat.st_mode)) - { - fprintf(stderr, "couldn't find config directory %s\n",cDir); - exit(1); - } - else if(!S_ISDIR(dDirStat.st_mode)) - { - fprintf(stderr, "couldn't find download directory %s\n",dDir); - exit(1); - } - tr_formatter_mem_init( MEM_K, MEM_K_STR, MEM_M_STR, MEM_G_STR, MEM_T_STR ); - tr_formatter_size_init( DISK_K,DISK_K_STR, DISK_M_STR, DISK_G_STR, DISK_T_STR ); - tr_formatter_speed_init( SPEED_K, SPEED_K_STR, SPEED_M_STR, SPEED_G_STR, SPEED_T_STR ); - tr_bencInitDict( &settings, 0 ); - tr_sessionLoadSettings( &settings, cDir, NULL); - tr_bencDictAddStr( &settings, TR_PREFS_KEY_DOWNLOAD_DIR, dDir ); - h = tr_sessionInit( "client", cDir, FALSE, &settings ); - } - //reset the SEEDING status to 0 if it's not null - char* updateString = "UPDATE FILE SET SEEDING=0 WHERE SEEDING=1"; - char* errMsg=NULL; - int rc= sqlite3_exec(db, updateString, NULL, NULL, &errMsg); - if(rc!=SQLITE_OK) - { - perror(errMsg); - exit; - } -} - -static -void seeding(void * args) -{ - tr_torrent *tor=args; - - const tr_stat * st; - const char * messageName[] = { NULL, "Tracker gave a warning:", - "Tracker gave an error:", - "Error:" }; - char downloadedImage[strlen(rootDir)+strlen(downloadDir)+1+strlen(tor->info.files[0].name)]; - sprintf(downloadedImage, "%s%s/%s", rootDir, downloadDir, tor->info.files[0].name); -printf(tor->info.files[0].name); - tr_torrentStart( tor ); - while(1) - { - tr_wait_msec( 200 ); - st = tr_torrentStat( tor ); - if( st->activity & TR_STATUS_STOPPED ) - break; - else if( st->activity & TR_STATUS_SEED ) - { - if(access(downloadedImage, F_OK)!=0)//the downloaded file has been deleted - { - unlink(downloadedImage); - unlink(tor->info.torrent); - //tr_torrentFree(tor); - char* resumeName=getResumeFilename(tor); - unlink(resumeName); - tr_free(resumeName); - tr_fdTorrentClose(tor->session, tor->uniqueId); - printf("%s stops seeding\n", downloadedImage); - return; - } - printf("%s is seeding\n", tor->info.torrent); - } - else if( (st->activity & TR_STATUS_CHECK_WAIT) || (st->activity & TR_STATUS_CHECK) ); - else - { - fprintf( stderr, "%s should be seeding\n", tor->info.torrent); - } - if( messageName[st->error] ) - { - fprintf( stderr, "\n%s: %s\n", messageName[st->error], st->errorString ); - } - } - tr_torrentFree(tor); -} - -int main(int argc, char* argv[]) -{ - if(argc==3) - { - rootDir = argv[1]; - database =argv[2]; - } - else - { - fprintf(stderr, "the arguments' amount is incorrent, we expect to clarify the root directory.\n"); - fprintf(stderr, "seeding ROOTDIRECTORY DATABASE_FILE\n"); - return -1; - } - char lockpath[strlen(rootDir)+strlen(configDir)+strlen("/lock")]; - sprintf(lockpath, "%s%s%s", rootDir, configDir, "/lock"); - - int fildes=open(lockpath, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH); - if(fildes==-1) - { - perror("fail to open the database!"); - return -1; - } - int status=lockf(fildes, F_TLOCK, 0); - if(status==-1) - { - perror("another seeding process is running!"); - return -1; - } - - - int rc = sqlite3_open(database, &db); - if(rc!=SQLITE_OK) - { - fprintf(stderr, "%s\n", sqlite3_errmsg(db)); - return -1; - } - else - printf("database %s is opened successfully.\n", database); - - sessionInit(rootDir); - - int rows=0; - int columns=0; - char **azResult; - char *queryMsg; - char* sql="SELECT * FROM FILE WHERE STATUS=1 AND SEEDING=0"; - while(1) - { - int queryResult=sqlite3_get_table(db, sql, &azResult,&rows, &columns, &queryMsg); - if(queryResult!=SQLITE_OK) - { - fprintf(stderr, "%s\n", sqlite3_errmsg(db)); - return -1; - } - else - sqlite3_free(queryMsg); - for(int i=0;iinfo.files[0].name); - tor->info.files[0].name=azResult[i*columns+columns]; - tr_threadNew( seeding, tor ); - } - sqlite3_free_table(azResult); - tr_wait_msec( 30000 );//check if there's new downloaded images every 30s - } - status=lockf(fildes, F_ULOCK, 0); - if(status==-1) - perror("fail to release the lock!"); -} diff --git a/bittorrent_jni/configure.ac b/bittorrent_jni/configure.ac deleted file mode 100644 index e59d00c..0000000 --- a/bittorrent_jni/configure.ac +++ /dev/null @@ -1,324 +0,0 @@ -m4_define([user_agent_prefix],[2.13]) -m4_define([peer_id_prefix],[-TR2130-]) - -AC_INIT([imageproxy], - [0.1], - [https://geni-orca.renci.org/trac/newticket]) -AC_SUBST(USERAGENT_PREFIX,[user_agent_prefix]) -AC_SUBST(PEERID_PREFIX,[peer_id_prefix]) - -m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) - -AC_CONFIG_MACRO_DIR([m4]) - -dnl AM_CONFIG_HEADER(config.h) -AC_CONFIG_SRCDIR(libtransmission/transmission.h) -AM_INIT_AUTOMAKE([1.9 tar-ustar]) -AC_PROG_LIBTOOL - -if test m4_substr(peer_id_prefix,6,1) = "0"; then - supported_build=yes - CPPFLAGS="$CPPFLAGS -DNDEBUG" -else - supported_build=no - if test "x$GCC" = "xyes" ; then - CFLAGS="$CFLAGS -g -O0" - CXXFLAGS="$CXXFLAGS -g -O0" - fi -fi -AM_CONDITIONAL(TR_UNSTABLE, test "x$supported_build" = "xno") - -## -## -## MANDATORY for everything -## -## -CURL_MINIMUM=7.15.4 -AC_SUBST(CURL_MINIMUM) -LIBEVENT_MINIMUM=1.4.9 -AC_SUBST(LIBEVENT_MINIUM) -OPENSSL_MINIMUM=0.9.4 -AC_SUBST(OPENSSL_MINIMUM) - -AC_PROG_CC -AC_PROG_CXX -AC_C_INLINE -if test "x$GCC" = "xyes" ; then - - CFLAGS="$CFLAGS -std=gnu99 -ggdb3 -Wall -W -Wpointer-arith -Wformat-security -Wcast-align -Wundef -Wcast-align -Wstrict-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wnested-externs -Wunused-parameter -Wwrite-strings -Waggregate-return -Winline -Wfloat-equal" - - dnl figure out gcc version - AC_MSG_CHECKING([gcc version]) - GCC_VERSION=`$CC -dumpversion` - GCC_MAJOR=`echo $GCC_VERSION | cut -d . -f1` - GCC_MINOR=`echo $GCC_VERSION | cut -d . -f2` - GCC_VERSION_NUM=`(expr $GCC_MAJOR "*" 100 + $GCC_MINOR) 2>/dev/null` - - AC_MSG_RESULT($GCC_VERSION) - if test $GCC_VERSION_NUM -ge 304; then - dnl these were added in 3.4 - CFLAGS="$CFLAGS -Wextra -Wdeclaration-after-statement -Winit-self" - fi - if test $GCC_VERSION_NUM -ge 403; then - dnl these were added in 4.3 - CFLAGS="$CFLAGS -Wvariadic-macros" - fi -fi - -AC_HEADER_STDC -AC_HEADER_TIME - -AC_CHECK_FUNCS([iconv_open pread pwrite lrintf strlcpy daemon dirname basename strcasecmp localtime_r fallocate64 posix_fallocate memmem strsep strtold syslog valloc getpagesize posix_memalign]) -AC_PROG_INSTALL -AC_PROG_MAKE_SET -ACX_PTHREAD - -if test "x$ac_cv_func_strtold" != "xyes" ; then - CPPFLAGS="$CPPFLAGS -Dstrtold=strtod" -fi - -AC_SEARCH_LIBS(cos, [m]) -AC_SEARCH_LIBS([socket], [socket net]) -AC_SEARCH_LIBS([gethostbyname], [nsl bind]) -PKG_CHECK_MODULES(OPENSSL, [openssl >= $OPENSSL_MINIMUM], , [CHECK_SSL()]) -PKG_CHECK_MODULES(LIBCURL, [libcurl >= $CURL_MINIMUM]) -AC_PATH_ZLIB - -AC_SYS_LARGEFILE -AC_CHECK_FUNCS([lseek64]) - - -dnl ---------------------------------------------------------------------------- -dnl -dnl posix_fadvise - -dnl can posix_fadvise be used -AC_CHECK_DECLS(posix_fadvise, [], [], [ -#define _XOPEN_SOURCE 600 -#include ]) -AC_CHECK_FUNCS([posix_fadvise]) - - -dnl ---------------------------------------------------------------------------- -dnl -dnl file monitoring for the daemon - -AC_CHECK_HEADER([sys/inotify.h], - [AC_CHECK_FUNC([inotify_init],[have_inotify="yes"],[have_inotify="no"])], - [have_inotify="no"]) -AC_ARG_WITH([inotify], - [AS_HELP_STRING([--with-inotify],[Enable inotify support (default=auto)])], - [want_inotify=${withval}], - [want_inotify=${have_inotify}]) -if test "x$want_inotify" = "xyes" ; then - if test "x$have_inotify" = "xyes"; then - AC_DEFINE([WITH_INOTIFY],[1]) - else - AC_MSG_ERROR(inotify not found!) - fi -fi - -AC_CHECK_HEADER([sys/event.h], - [AC_CHECK_FUNC([kqueue],[have_kqueue="yes"],[have_kqueue="no"])], - [have_kqueue="no"]) -AC_ARG_WITH([kqueue], - [AS_HELP_STRING([--with-kqueue],[Enable kqueue support (default=auto)])], - [want_kqueue=${withval}], - [want_kqueue=${have_kqueue}]) -if test "x$want_kqueue" = "xyes" ; then - if test "x$have_kqueue" = "xyes"; then - AC_DEFINE([WITH_KQUEUE],[1]) - else - AC_MSG_ERROR(kqueue not found!) - fi -fi - -AC_CHECK_HEADERS([xfs/xfs.h]) - - -dnl ---------------------------------------------------------------------------- -dnl -dnl va_copy - -AC_MSG_CHECKING([how to copy va_list]) -AC_TRY_LINK([#include ], [va_list ap1, ap2; va_copy(ap1, ap2);], - AC_MSG_RESULT([va_copy]), - [ AH_TEMPLATE([va_copy], [define if va_copy is not available]) - AC_TRY_LINK([#include ], [va_list ap1, ap2; __va_copy(ap1, ap2);], - [ AC_DEFINE([va_copy], [__va_copy]) - AC_MSG_RESULT([__va_copy])], - [ AC_DEFINE([va_copy(dest,src)], [memcpy(&dest,&src,sizeof(va_list))]) - AC_MSG_RESULT([memcpy])] - ) -]) - - -dnl libevent likes to link against librt if possible -dnl for clock_gettime() and clock_settime() -dnl TODO(libevent2): this can probably be removed after -dnl we switch to libevent2, since it will have PKG_CONFIG -AC_CHECK_LIB([rt], - [clock_gettime], - [libevent_extra_libs="-lrt"], - [libevent_extra_libs=""]) - - -dnl libevent -dnl if the user specified LIBEVENT_LIBS or -if test -n "$LIBEVENT_LIBS"; then - user_specified_libevent=yes -elif test -n "$LIBEVENT_CFLAGS"; then - user_specified_libevent=yes -fi -if test "x$user_specified_libevent" = "xyes"; then - AC_MSG_NOTICE([Using user-specified LIBEVENT_LIBS and LIBEVENT_CFLAGS]) -else - AC_CHECK_LIB([event],[evutil_vsnprintf], - [], - [AC_MSG_ERROR(libevent $LIBEVENT_MINIMUM or higher not found!)], - [$libevent_extra_libs]) - AC_CHECK_HEADER([event-config.h],[], - [AC_MSG_ERROR(event-config.h not found!)]) - LIBEVENT_CFLAGS="" - LIBEVENT_LIBS="-levent $libevent_extra_libs" -fi -AC_ARG_VAR([LIBEVENT_CFLAGS], [C compiler flags for LIBEVENT, overriding pkg-config])dnl -AC_ARG_VAR([LIBEVENT_LIBS], [linker flags for LIBEVENT, overriding pkg-config])dnl - -dnl --------------------------------------------------------------------------- -dnl libsqlite3 -dnl if the user specified LIBSQLITE3_LIBS or -if test -n "$LIBSQLITE3_LIBS"; then - user_specified_libsqlite3=yes -elif test -n "$LIBSQLITE3_CFLAGS"; then - user_specified_libsqlite3=yes -fi -if test "x$user_specified_libsqlite3" = "xyes"; then - AC_MSG_NOTICE([Using user-specified LIBSQLITE3_LIBS and LIBSQLITE3_CFLAGS]) -else - AC_CHECK_LIB([sqlite3],[sqlite3_open], - [], - [AC_MSG_ERROR(libsqlite3 not found!)], - [-lsqlite3]) - AC_CHECK_HEADER([sqlite3.h],[], - [AC_MSG_ERROR(sqlite3.h not found!)]) - LIBSQLITE3_CFLAGS="" - LIBSQLITE3_LIBS="-lsqlite3" -fi -AC_ARG_VAR([LIBSQLITE3_CFLAGS], [C compiler flags for LIBSQLITE3, overriding pkg-config])dnl -AC_ARG_VAR([LIBSQLITE3_LIBS], [linker flags for LIBSQLITE3, overriding pkg-config])dnl - -dnl ---------------------------------------------------------------------------- -dnl -dnl Java - in truth, all we need is jni.h - -AC_ARG_WITH([jdk], - [AS_HELP_STRING([--with-jdk=DIR],[Path to JDK])], - [jdk_dir=${withval}], - [jdk_dir=]) -JAVAINCDIR="" -if test -z "$jdk_dir"; then - JAVAINCDIR="/usr/j2sdk*/include /usr/local/j2sdk*/include /usr/jdk*/include /usr/local/jdk*/include /opt/j2sdk*/include /opt/jdk*/include /usr/java/include /usr/java/j2sdk*/include /usr/java/jdk*/include /usr/local/java/include /opt/java/include /usr/include/java /usr/local/include/java /usr/lib/java/include /System/Library/Frameworks/JavaVM.framework/Headers/" -else - JAVAINCDIR="${jdk_dir}/include" -fi -AC_MSG_CHECKING(for java include file jni.h) -JAVA_CFLAGS="" -for d in $JAVAINCDIR ; do - if test -r $d/jni.h ; then - AC_MSG_RESULT($d) - JAVAINCDIR=$d - JAVA_CFLAGS="-I$d" - break - fi -done -dnl Bomb out if no Java includes found. -if test "$JAVA_CFLAGS" = ""; then - AC_MSG_ERROR(JDK header files not found. A valid JDK is required.) -else -dnl now look for /jni_md.h - AC_MSG_CHECKING(for java include file jni_md.h) - JAVAMDDIR=`find $JAVAINCDIR -follow -name jni_md.h -print` - if test "$JAVAMDDIR" = "" ; then - AC_MSG_ERROR(jni.h found, but jni_md.h was not. Please verify your JDK is installed correctly.) - else - JAVAMDDIR=`dirname $JAVAMDDIR` - JAVA_CFLAGS="${JAVA_CFLAGS} -I$JAVAMDDIR" - AC_MSG_RESULT($JAVAMDDIR) - fi -fi -AC_SUBST(JAVA_CFLAGS) - -dnl ---------------------------------------------------------------------------- -dnl -dnl dht - -DHT_CFLAGS="-I\$(top_srcdir)/third-party/dht" -DHT_LIBS="\$(top_builddir)/third-party/dht/libdht.la" -AC_SUBST(DHT_CFLAGS) -AC_SUBST(DHT_LIBS) - -dnl ---------------------------------------------------------------------------- -dnl -dnl Intltool - -#IT_PROG_INTLTOOL([0.35.0],[no-xml]) -AC_CHECK_HEADERS([libintl.h]) -AC_SUBST(INTLLIBS) - -dnl ---------------------------------------------------------------------------- -dnl -dnl platform-specific stuff. - -AC_CANONICAL_HOST -have_darwin="no" -have_msw="no" -case $host_os in - - *mingw32*) - have_msw="yes" - CXXFLAGS="$CXXFLAGS -mms-bitfields -mwin32 -mwindows" - CPPFLAGS="$CPPFLAGS -DWIN32 -D_WIN32 -DWIN32_LEAN_AND_MEAN" - LIBS="$LIBS -liphlpapi -lshell32 -lws2_32" - transmissionlocaledir="locale" - if test -z "$host_alias"; then - hostaliaswindres= - else - hostaliaswindres="$host_alias-windres"; - fi - AC_CHECK_TOOL(WINDRES, windres) - ;; - - *darwin*) - have_darwin="yes" - CFLAGS="-DMACOSX $CFLAGS" - ;; - -esac - -if test "x$have_darwin" = "xyes"; then - AC_DEFINE([HAVE_DARWIN], 1) -fi -if test "x$have_msw" = "xyes"; then - AC_DEFINE([HAVE_MSW], 1) -fi -AM_CONDITIONAL(WIN32, test "x$have_msw" = "xyes") - -dnl ---------------------------------------------------------------------------- -dnl -dnl Generate the output - -AC_CONFIG_FILES([Makefile - cli/Makefile - libtransmission/Makefile - third-party/Makefile - third-party/miniupnp/Makefile - third-party/libnatpmp/Makefile - third-party/dht/Makefile]) - -ac_configure_args="$ac_configure_args --enable-static --disable-shared -q" -AC_OUTPUT - -echo " - Configuration complete. Type \"make\" to build. -" diff --git a/bittorrent_jni/prep_build.sh b/bittorrent_jni/prep_build.sh deleted file mode 100755 index 172a6cb..0000000 --- a/bittorrent_jni/prep_build.sh +++ /dev/null @@ -1,48 +0,0 @@ -#!/bin/sh -export TRANSMISSION_VERSION=2.13 - -if [ ! -e external ]; then - mkdir external -fi -cd external - -echo "Fetching transmission-$TRANSMISSION_VERSION..." -WGET=`which wget` -CURL=`which curl` -if [ "$WGET" != "" ] && [ -x $WGET ]; then - $WGET http://download.m0k.org/transmission/files/transmission-$TRANSMISSION_VERSION.tar.bz2 -else if [ "$CURL" != "" ] && [ -x $CURL ]; then - $CURL http://download.m0k.org/transmission/files/transmission-$TRANSMISSION_VERSION.tar.bz2 > transmission-$TRANSMISSION_VERSION.tar.bz2 - else - echo "Unable to find wget or curl, exiting" - exit -1 - fi -fi - -if [ "$?" != "0" ]; then - echo "Unable to retrieve BT code, exiting" - exit -1 -fi - -echo -echo "Untarring and re-arranging..." -tar -xjf transmission-$TRANSMISSION_VERSION.tar.bz2 - -mv transmission-$TRANSMISSION_VERSION/libtransmission .. -mv transmission-$TRANSMISSION_VERSION/third-party .. -mv transmission-$TRANSMISSION_VERSION/m4 .. - -cd .. - -cd m4 -rm libtool.m4 ltoptions.m4 ltsugar.m4 lt~obsolete.m4 ltversion.m4 -cd .. - -echo -echo "Patching and running autoreconf procedures..." -patch -p1 < transmission_find_port.patch -patch -p1 < transmission_shared_lib.patch -autoreconf --install --force - -echo -echo "Done. Now, please run ./configure" diff --git a/bittorrent_jni/transmission_find_port.patch b/bittorrent_jni/transmission_find_port.patch deleted file mode 100644 index 3e0f714..0000000 --- a/bittorrent_jni/transmission_find_port.patch +++ /dev/null @@ -1,25 +0,0 @@ -diff -ru 1/libtransmission/net.c 2/libtransmission/net.c ---- 1/libtransmission/net.c 2010-12-09 14:53:19.000000000 -0500 -+++ 2/libtransmission/net.c 2011-02-22 15:42:23.903864918 -0500 -@@ -386,7 +386,7 @@ - } - #endif - -- addrlen = setup_sockaddr( addr, htons( port ), &sock ); -+flag: addrlen = setup_sockaddr( addr, htons( port ), &sock ); - if( bind( fd, (struct sockaddr *) &sock, addrlen ) ) { - const int err = sockerrno; - if( !suppressMsgs ) -@@ -395,7 +395,11 @@ - const char * hint; - - if( err == EADDRINUSE ) -+ { - hint = _( "Is another copy of Transmission already running?" ); -+ port++; -+ goto flag; -+ } - else - hint = NULL; - -Only in 2/libtransmission: .net.c.swp diff --git a/bittorrent_jni/transmission_shared_lib.patch b/bittorrent_jni/transmission_shared_lib.patch deleted file mode 100644 index 243f2bc..0000000 --- a/bittorrent_jni/transmission_shared_lib.patch +++ /dev/null @@ -1,68 +0,0 @@ -diff -ru 1/libtransmission/Makefile.am 2/libtransmission/Makefile.am ---- 1/libtransmission/Makefile.am 2010-12-09 14:53:19.000000000 -0500 -+++ 2/libtransmission/Makefile.am 2011-02-22 22:55:18.508019352 -0500 -@@ -13,9 +13,9 @@ - @PTHREAD_CFLAGS@ \ - @ZLIB_CFLAGS@ - --noinst_LIBRARIES = libtransmission.a -+noinst_LTLIBRARIES = libtransmission.la - --libtransmission_a_SOURCES = \ -+libtransmission_la_SOURCES = \ - announcer.c \ - bandwidth.c \ - bencode.c \ -@@ -133,9 +133,9 @@ - @ZLIB_LDFLAGS@ - - apps_ldadd = \ -- ./libtransmission.a \ -- $(top_builddir)/third-party/miniupnp/libminiupnp.a \ -- $(top_builddir)/third-party/libnatpmp/libnatpmp.a \ -+ ./libtransmission.la \ -+ $(top_builddir)/third-party/miniupnp/libminiupnp.la \ -+ $(top_builddir)/third-party/libnatpmp/libnatpmp.la \ - @INTLLIBS@ \ - @DHT_LIBS@ \ - @LIBCURL_LIBS@ \ -diff -ru 1/third-party/dht/Makefile.am 2/third-party/dht/Makefile.am ---- 1/third-party/dht/Makefile.am 2010-12-09 14:53:33.000000000 -0500 -+++ 2/third-party/dht/Makefile.am 2011-02-22 22:49:20.033720845 -0500 -@@ -1,6 +1,6 @@ - AM_CFLAGS = @PTHREAD_CFLAGS@ - --noinst_LIBRARIES = libdht.a --libdht_a_SOURCES = dht.c -+noinst_LTLIBRARIES = libdht.la -+libdht_la_SOURCES = dht.c - noinst_HEADERS = dht.h - EXTRA_DIST = CHANGES dht-example.c LICENCE README -diff -ru 1/third-party/libnatpmp/Makefile.am 2/third-party/libnatpmp/Makefile.am ---- 1/third-party/libnatpmp/Makefile.am 2010-12-09 14:53:34.000000000 -0500 -+++ 2/third-party/libnatpmp/Makefile.am 2011-02-22 22:50:22.139267532 -0500 -@@ -1,8 +1,8 @@ --noinst_LIBRARIES = libnatpmp.a -+noinst_LTLIBRARIES = libnatpmp.la - - AM_CFLAGS = @PTHREAD_CFLAGS@ -DENABLE_STRNATPMPERR - --libnatpmp_a_SOURCES = \ -+libnatpmp_la_SOURCES = \ - getgateway.c \ - natpmp.c \ - wingettimeofday.c -diff -ru 1/third-party/miniupnp/Makefile.am 2/third-party/miniupnp/Makefile.am ---- 1/third-party/miniupnp/Makefile.am 2010-12-09 14:53:33.000000000 -0500 -+++ 2/third-party/miniupnp/Makefile.am 2011-02-22 22:50:43.277751848 -0500 -@@ -1,8 +1,8 @@ --noinst_LIBRARIES = libminiupnp.a -+noinst_LTLIBRARIES = libminiupnp.la - - AM_CFLAGS = @PTHREAD_CFLAGS@ -DNDEBUG - --libminiupnp_a_SOURCES = \ -+libminiupnp_la_SOURCES = \ - connecthostport.c \ - igd_desc_parse.c \ - minisoap.c \ diff --git a/scripts/nova_deregister.sh b/scripts/nova_deregister.sh index c42010d..5a141e1 100755 --- a/scripts/nova_deregister.sh +++ b/scripts/nova_deregister.sh @@ -49,7 +49,7 @@ echo "[$DATE] Parameter #1(Image ID) is $1" >> $IMAGEPROXY_LOG IMG_ID=$1 ## Delete the image -DELETE_CMD="glance -f delete $IMG_ID" +DELETE_CMD="openstack image delete $IMG_ID" echo "[$DATE] Deleting image..." >> $IMAGEPROXY_LOG echo "[$DATE] $DELETE_CMD" >> $IMAGEPROXY_LOG RESULT=`$DELETE_CMD 2>> $IMAGEPROXY_LOG` diff --git a/scripts/nova_register.sh b/scripts/nova_register.sh index 7d0fb63..5e5d7bf 100755 --- a/scripts/nova_register.sh +++ b/scripts/nova_register.sh @@ -59,14 +59,16 @@ echo "[$DATE] Parameter #2(Bukkit name) is $2" >> $IMAGEPROXY_LOG BUKKIT_NAME=$2 COMPRESSED_FILESYSTEM=false -ADD_PARAM="container_format=ami disk_format=ami" +ADD_PARAM="--disk-format ami --container-format ami" echo "[$DATE] Parameter #3(Image type) is $3" >> $IMAGEPROXY_LOG if [ "$3" = "KERNEL" ]; then - ADD_PARAM="container_format=aki disk_format=aki" + ADD_PARAM="--disk-format aki --container-format aki" elif [ "$3" = "RAMDISK" ]; then - ADD_PARAM="container_format=ari disk_format=ari" + ADD_PARAM="--disk-format ari --container-format ari" elif [ "$3" = "ZFILESYSTEM" ]; then COMPRESSED_FILESYSTEM=true +elif [ "$3" = "QCOW2" ]; then + ADD_PARAM="--disk-format qcow2 --container-format bare" fi echo "[$DATE] Parameter #4(Bundle path) is $4" >> $IMAGEPROXY_LOG @@ -137,7 +139,7 @@ fi ## Add the image into glance IMG_ID="$BUKKIT_NAME/$(basename $IMG_LOCATION)" -ADD_CMD="cat $IMG_LOCATION | glance add name=$IMG_ID --silent-upload is_public=true $ADD_PARAM" +ADD_CMD="openstack image create $IMG_ID --file $IMG_LOCATION $ADD_PARAM --public" echo "[$DATE] Adding image..." >> $IMAGEPROXY_LOG echo "[$DATE] $ADD_CMD" >> $IMAGEPROXY_LOG RESULT=`eval $ADD_CMD 2>> $IMAGEPROXY_LOG` @@ -147,7 +149,7 @@ check_exit_code echo "[$DATE] $RESULT" >> $IMAGEPROXY_LOG ## Extract the image's UUID -IMG_UUID=`echo $RESULT | sed -e 's/^.*ID:\ //'` +IMG_UUID=`openstack image list -f value | grep $IMG_ID | awk '{print $1}'` # Clean up working dir by calling the trap kill -USR2 $$ diff --git a/src/main/java/orca/imageproxy/BTDownload.java b/src/main/java/orca/imageproxy/BTDownload.java index edc260e..f2dac1e 100644 --- a/src/main/java/orca/imageproxy/BTDownload.java +++ b/src/main/java/orca/imageproxy/BTDownload.java @@ -86,7 +86,6 @@ private BTDownload() throws Exception{ l.info("Available space for downloads = "+ CACHE_SIZE + " bytes"); new File(BTDownload.DOWNLOADFOLDER).mkdir(); - initSession(imageproxyHome); //clear the files in downloading status l.info("attempting to clear the downloading files left by the last nasty crash"); @@ -388,8 +387,6 @@ private String httpdownloadfromURL(String surl, String signature) throws SQLExce return correctHash; } - public native void initSession(String rootfolder); - /** * get length of a file to be downloaded by bt protocol * @param btUrl @@ -507,8 +504,4 @@ private void deleteIncompleteFiles(){ filelist[i].delete(); } } - - static { - System.loadLibrary("btclient"); // the bt c library we are hooking up - } } diff --git a/src/main/java/orca/imageproxy/Globals.java b/src/main/java/orca/imageproxy/Globals.java index b302d52..aee260c 100644 --- a/src/main/java/orca/imageproxy/Globals.java +++ b/src/main/java/orca/imageproxy/Globals.java @@ -25,6 +25,7 @@ public class Globals { public static final String FILE_SYSTEM_IMAGE_KEY = "FILESYSTEM"; public static final String ZFILE_SYSTEM_IMAGE_KEY = "ZFILESYSTEM"; + public static final String QCOW2_SYSTEM_IMAGE_KEY = "QCOW2"; public static final String KERNEL_IMAGE_KEY = "KERNEL"; public static final String RAMDISK_IMAGE_KEY = "RAMDISK"; public static final String IMAGE_INPROGRESS = "INPROGRESS"; diff --git a/src/main/java/orca/imageproxy/RegistrationScript.java b/src/main/java/orca/imageproxy/RegistrationScript.java index 935207a..11fbb9e 100644 --- a/src/main/java/orca/imageproxy/RegistrationScript.java +++ b/src/main/java/orca/imageproxy/RegistrationScript.java @@ -23,42 +23,42 @@ public class RegistrationScript { - private static final String testModeProperty = "impTestMode"; + private static final String testModeProperty = "impTestMode"; - protected static final String registerScriptProperty = "registerScriptProperty"; - - protected static final String DEFAULT_REGISTER_SCRIPT = "scripts/register.sh"; - - protected static final String bukkitNameProperty = "eucaBukkitName"; - - protected static final String DEFAULT_BUKKIT_NAME = "imageproxy.bukkit"; + protected static final String registerScriptProperty = "registerScriptProperty"; + + protected static final String DEFAULT_REGISTER_SCRIPT = "scripts/register.sh"; + + protected static final String bukkitNameProperty = "eucaBukkitName"; + + protected static final String DEFAULT_BUKKIT_NAME = "imageproxy.bukkit"; - protected BTDownload btDownload; + protected BTDownload btDownload; - protected Logger l; - - private boolean testMode = false; - - private int testModeSleep = 30000; // in milliseconds - - protected SqliteDatabase db; + protected Logger l; + + private boolean testMode = false; + + private int testModeSleep = 30000; // in milliseconds + + protected SqliteDatabase db; - public RegistrationScript() throws Exception { - try{ - db = SqliteDatabase.getInstance(); - l = Logger.getLogger(this.getClass()); - Properties p = Globals.getInstance().getProperties(); - if (p.containsKey(testModeProperty)) { - String testModeString = p.getProperty(testModeProperty); - if (testModeString.toLowerCase().equals("true") || - testModeString.toLowerCase().equals("yes")) { - testMode = true; - if (p.containsKey("testModeSleep")) - testModeSleep = Integer.parseInt(p.getProperty("testModeSleep")) * 1000; - } - } - btDownload = BTDownload.getInstance(); - }catch(Exception exception){ + public RegistrationScript() throws Exception { + try{ + db = SqliteDatabase.getInstance(); + l = Logger.getLogger(this.getClass()); + Properties p = Globals.getInstance().getProperties(); + if (p.containsKey(testModeProperty)) { + String testModeString = p.getProperty(testModeProperty); + if (testModeString.toLowerCase().equals("true") || + testModeString.toLowerCase().equals("yes")) { + testMode = true; + if (p.containsKey("testModeSleep")) + testModeSleep = Integer.parseInt(p.getProperty("testModeSleep")) * 1000; + } + } + btDownload = BTDownload.getInstance(); + }catch(Exception exception){ l.error("Exception during initialization."); l.error(exception.toString(), exception); throw exception; @@ -90,6 +90,8 @@ public String RegisterImage(String url, String signature) throws Exception{ Double uniq = Math.floor(Math.random() * 1000); imageIds.put(Globals.FILE_SYSTEM_IMAGE_KEY, url + uniq.intValue()); uniq = Math.floor(Math.random() * 1000); + imageIds.put(Globals.QCOW2_SYSTEM_IMAGE_KEY, url + uniq.intValue()); + uniq = Math.floor(Math.random() * 1000); imageIds.put(Globals.KERNEL_IMAGE_KEY, url + uniq.intValue()); uniq = Math.floor(Math.random() * 1000); imageIds.put(Globals.RAMDISK_IMAGE_KEY, url + uniq.intValue()); @@ -106,7 +108,7 @@ public String RegisterImage(String url, String signature) throws Exception{ hash + " for metadata file at URL: " + url); } - String emi, eki, eri; + String emi, eki, eri, qcow2; try{ l.info("Entering download and registration process"); @@ -117,6 +119,10 @@ public String RegisterImage(String url, String signature) throws Exception{ HashMap> downloadRegisterTasks = new HashMap>(); + if (imageInfo.containsKey(Globals.QCOW2_SYSTEM_IMAGE_KEY)) { + downloadRegisterTasks.put(Globals.QCOW2_SYSTEM_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.QCOW2_SYSTEM_IMAGE_KEY)); + } + if (imageInfo.containsKey(Globals.FILE_SYSTEM_IMAGE_KEY)) { downloadRegisterTasks.put(Globals.FILE_SYSTEM_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.FILE_SYSTEM_IMAGE_KEY)); } @@ -124,36 +130,43 @@ else if (imageInfo.containsKey(Globals.ZFILE_SYSTEM_IMAGE_KEY)) { downloadRegisterTasks.put(Globals.ZFILE_SYSTEM_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.ZFILE_SYSTEM_IMAGE_KEY)); } else { - l.error("Valid filesystem image information could not be found in the metadata."); - //return Globals.ERROR_CODE; - throw new Exception("Valid filesystem image information could not be found in the metadata."); + if (!imageInfo.containsKey(Globals.QCOW2_SYSTEM_IMAGE_KEY)) { + l.error("Valid filesystem image information could not be found in the metadata."); + //return Globals.ERROR_CODE; + throw new Exception("Valid filesystem image information could not be found in the metadata."); + } } if(imageInfo.containsKey(Globals.KERNEL_IMAGE_KEY)){ - l.info("Kernel image information available"); - downloadRegisterTasks.put(Globals.KERNEL_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.KERNEL_IMAGE_KEY)); + l.info("Kernel image information available"); + downloadRegisterTasks.put(Globals.KERNEL_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.KERNEL_IMAGE_KEY)); } if(imageInfo.containsKey(Globals.RAMDISK_IMAGE_KEY)){ - l.info("Ramdisk image information available"); - downloadRegisterTasks.put(Globals.RAMDISK_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.RAMDISK_IMAGE_KEY)); + l.info("Ramdisk image information available"); + downloadRegisterTasks.put(Globals.RAMDISK_IMAGE_KEY, downloadAndRegister(imageInfo, Globals.RAMDISK_IMAGE_KEY)); } - // Future futStr = downloadRegisterTasks.get(Globals.FILE_SYSTEM_IMAGE_KEY); if (futStr == null) futStr = downloadRegisterTasks.get(Globals.ZFILE_SYSTEM_IMAGE_KEY); - emi = futStr.get(); - imageIds.put(Globals.FILE_SYSTEM_IMAGE_KEY, emi); + if(futStr != null) { + emi = futStr.get(); + imageIds.put(Globals.FILE_SYSTEM_IMAGE_KEY, emi); + } + if (imageInfo.containsKey(Globals.QCOW2_SYSTEM_IMAGE_KEY)) { + qcow2 = downloadRegisterTasks.get(Globals.QCOW2_SYSTEM_IMAGE_KEY).get(); + imageIds.put(Globals.QCOW2_SYSTEM_IMAGE_KEY, qcow2); + } if (imageInfo.containsKey(Globals.KERNEL_IMAGE_KEY)) { - eki = downloadRegisterTasks.get(Globals.KERNEL_IMAGE_KEY).get(); - imageIds.put(Globals.KERNEL_IMAGE_KEY, eki); + eki = downloadRegisterTasks.get(Globals.KERNEL_IMAGE_KEY).get(); + imageIds.put(Globals.KERNEL_IMAGE_KEY, eki); } if (imageInfo.containsKey(Globals.RAMDISK_IMAGE_KEY)) { - eri = downloadRegisterTasks.get(Globals.RAMDISK_IMAGE_KEY).get(); - imageIds.put(Globals.RAMDISK_IMAGE_KEY, eri); + eri = downloadRegisterTasks.get(Globals.RAMDISK_IMAGE_KEY).get(); + imageIds.put(Globals.RAMDISK_IMAGE_KEY, eri); } } catch (Exception exception) { @@ -162,13 +175,15 @@ else if (imageInfo.containsKey(Globals.ZFILE_SYSTEM_IMAGE_KEY)) { } } - - l.info("Filesystem Image id: " + imageIds.get(Globals.FILE_SYSTEM_IMAGE_KEY)); + if (imageIds.get(Globals.FILE_SYSTEM_IMAGE_KEY) != null) + l.info("Filesystem Image id: " + imageIds.get(Globals.FILE_SYSTEM_IMAGE_KEY)); + if (imageIds.get(Globals.QCOW2_SYSTEM_IMAGE_KEY) != null) + l.info("Qcow2 Image id: " + imageIds.get(Globals.QCOW2_SYSTEM_IMAGE_KEY)); if (imageIds.get(Globals.KERNEL_IMAGE_KEY) != null) - l.info("Kernel Image id: " + imageIds.get(Globals.KERNEL_IMAGE_KEY)); + l.info("Kernel Image id: " + imageIds.get(Globals.KERNEL_IMAGE_KEY)); if (imageIds.get(Globals.RAMDISK_IMAGE_KEY) != null) - l.info("Ramdisk Image id: " + imageIds.get(Globals.RAMDISK_IMAGE_KEY)); - + l.info("Ramdisk Image id: " + imageIds.get(Globals.RAMDISK_IMAGE_KEY)); + return toString(imageIds); } catch (Exception exception) { @@ -176,155 +191,156 @@ else if (imageInfo.containsKey(Globals.ZFILE_SYSTEM_IMAGE_KEY)) { throw exception; } } - - private Future downloadAndRegister(Map> imageInfo, String type) throws Exception { - - DownloadRegister downloadRegister = new DownloadRegister(); - downloadRegister.setImageInfo(imageInfo); - downloadRegister.setType(type); - - ExecutorService executorService = Executors.newSingleThreadExecutor(); - Future downloadRegisterTask = executorService.submit(downloadRegister); - executorService.shutdown(); - - return downloadRegisterTask; - } - - /** - * - * @param metadataFilePath - * @return - * @throws Exception - */ - private Map> parseMetadata(String metadataFilePath) throws Exception { - - List validImageTypes = new ArrayList(); - validImageTypes.add(Globals.FILE_SYSTEM_IMAGE_KEY); - validImageTypes.add(Globals.ZFILE_SYSTEM_IMAGE_KEY); - validImageTypes.add(Globals.KERNEL_IMAGE_KEY); - validImageTypes.add(Globals.RAMDISK_IMAGE_KEY); - - Map> imageInfo = new HashMap>(); - - try { + + private Future downloadAndRegister(Map> imageInfo, String type) throws Exception { + + DownloadRegister downloadRegister = new DownloadRegister(); + downloadRegister.setImageInfo(imageInfo); + downloadRegister.setType(type); + + ExecutorService executorService = Executors.newSingleThreadExecutor(); + Future downloadRegisterTask = executorService.submit(downloadRegister); + executorService.shutdown(); + + return downloadRegisterTask; + } + + /** + * + * @param metadataFilePath + * @return + * @throws Exception + */ + private Map> parseMetadata(String metadataFilePath) throws Exception { + + List validImageTypes = new ArrayList(); + validImageTypes.add(Globals.FILE_SYSTEM_IMAGE_KEY); + validImageTypes.add(Globals.ZFILE_SYSTEM_IMAGE_KEY); + validImageTypes.add(Globals.QCOW2_SYSTEM_IMAGE_KEY); + validImageTypes.add(Globals.KERNEL_IMAGE_KEY); + validImageTypes.add(Globals.RAMDISK_IMAGE_KEY); + + Map> imageInfo = new HashMap>(); + + try { - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - DocumentBuilder db = dbf.newDocumentBuilder(); - - Document doc = db.parse(new File(metadataFilePath)); - doc.getDocumentElement().normalize(); - - l.info("Root element " + doc.getDocumentElement().getNodeName()); - - l.info("Information of all images"); - - NodeList imgNodeList = doc.getElementsByTagName("image"); - - String type, signature, url; - - for (int itr = 0; itr < imgNodeList.getLength(); itr++) { + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + DocumentBuilder db = dbf.newDocumentBuilder(); + + Document doc = db.parse(new File(metadataFilePath)); + doc.getDocumentElement().normalize(); + + l.info("Root element " + doc.getDocumentElement().getNodeName()); + + l.info("Information of all images"); + + NodeList imgNodeList = doc.getElementsByTagName("image"); + + String type, signature, url; + + for (int itr = 0; itr < imgNodeList.getLength(); itr++) { - Node imgNode = imgNodeList.item(itr); - - if (imgNode.getNodeType() == Node.ELEMENT_NODE) { - - Element imgElmnt = (Element) imgNode; + Node imgNode = imgNodeList.item(itr); + + if (imgNode.getNodeType() == Node.ELEMENT_NODE) { + + Element imgElmnt = (Element) imgNode; - NodeList imgUrlElmntLst = imgElmnt.getElementsByTagName("url"); - Element imgUrlElmnt = (Element) imgUrlElmntLst.item(0); - NodeList imgUrl = imgUrlElmnt.getChildNodes(); - if (imgUrl.getLength() != 0) { - url = ((Node) imgUrl.item(0)).getNodeValue().trim(); - if (url.equals("")) { - l.info("URL element cannot be empty."); - continue; - } - else { - l.info("URL: " + url); - } - } - else { - l.info("URL element missing."); - continue; - } - - NodeList imgTypeElmntLst = imgElmnt.getElementsByTagName("type"); - Element imgTypeElmnt = (Element) imgTypeElmntLst.item(0); - NodeList imgType = imgTypeElmnt.getChildNodes(); - if (imgType.getLength() != 0) { - type = ((Node) imgType.item(0)).getNodeValue().trim(); - if (validImageTypes.contains(type)) { - l.info("Image Type: " + type); - } - else { - l.info("Invalid image type: \"" + type + - "\" for image URL: " + url); - continue; - } - } - else { - l.info("Type element missing for image URL: " + url); - continue; - } - - NodeList imgSignElmntLst = - imgElmnt.getElementsByTagName("signature"); - Element imgSignElmnt = (Element) imgSignElmntLst.item(0); - NodeList imgSign = imgSignElmnt.getChildNodes(); - if (imgSign.getLength() != 0) { - signature = ((Node) imgSign.item(0)).getNodeValue().trim(); - if (signature.equals("")) { - l.info("Signature element cannot be empty " + - "for image URL: " + url); - continue; - } - else { - l.info("Signature: " + signature); - } - } - else { - l.info("Signature element missing for image URL: " + url); - continue; - } - - imageInfo.put(type, new Pair(signature, url)); - } - } - - } - catch (Exception exception){ - l.error("Exception while parsing metadata."); - throw exception; - } - - return imageInfo; - } - - /** - * Calls the functions to download the required file - * @param signature - * @param url - * @return signature and url of the file to be downloaded - * @throws IOException - * @throws InterruptedException - */ + NodeList imgUrlElmntLst = imgElmnt.getElementsByTagName("url"); + Element imgUrlElmnt = (Element) imgUrlElmntLst.item(0); + NodeList imgUrl = imgUrlElmnt.getChildNodes(); + if (imgUrl.getLength() != 0) { + url = ((Node) imgUrl.item(0)).getNodeValue().trim(); + if (url.equals("")) { + l.info("URL element cannot be empty."); + continue; + } + else { + l.info("URL: " + url); + } + } + else { + l.info("URL element missing."); + continue; + } + + NodeList imgTypeElmntLst = imgElmnt.getElementsByTagName("type"); + Element imgTypeElmnt = (Element) imgTypeElmntLst.item(0); + NodeList imgType = imgTypeElmnt.getChildNodes(); + if (imgType.getLength() != 0) { + type = ((Node) imgType.item(0)).getNodeValue().trim(); + if (validImageTypes.contains(type)) { + l.info("Image Type: " + type); + } + else { + l.info("Invalid image type: \"" + type + + "\" for image URL: " + url); + continue; + } + } + else { + l.info("Type element missing for image URL: " + url); + continue; + } + + NodeList imgSignElmntLst = + imgElmnt.getElementsByTagName("signature"); + Element imgSignElmnt = (Element) imgSignElmntLst.item(0); + NodeList imgSign = imgSignElmnt.getChildNodes(); + if (imgSign.getLength() != 0) { + signature = ((Node) imgSign.item(0)).getNodeValue().trim(); + if (signature.equals("")) { + l.info("Signature element cannot be empty " + + "for image URL: " + url); + continue; + } + else { + l.info("Signature: " + signature); + } + } + else { + l.info("Signature element missing for image URL: " + url); + continue; + } + + imageInfo.put(type, new Pair(signature, url)); + } + } + + } + catch (Exception exception){ + l.error("Exception while parsing metadata."); + throw exception; + } + + return imageInfo; + } + + /** + * Calls the functions to download the required file + * @param signature + * @param url + * @return signature and url of the file to be downloaded + * @throws IOException + * @throws InterruptedException + */ Pair download(String signature, String url) throws Exception { - - l.info("Downloading file with signature: " + signature + " from url: " + url); - - // calling function to download file - Pair downloadInfo = btDownload.downloadFile(url, signature); - - l.info("File downloaded. Path: " + downloadInfo.getFirst() + " , Signature: " + downloadInfo.getSecond()); + + l.info("Downloading file with signature: " + signature + " from url: " + url); + + // calling function to download file + Pair downloadInfo = btDownload.downloadFile(url, signature); + + l.info("File downloaded. Path: " + downloadInfo.getFirst() + " , Signature: " + downloadInfo.getSecond()); - return downloadInfo; - } - - /** + return downloadInfo; + } + + /** * Serializes a properties list to a string * @param properties The properties list * @return The string representation of this properties list - * @throws IOException + * @throws IOException */ private static String toString(Properties properties) throws IOException {