00001
00002
00003
00004
00005
00006
00007
00008 #include "config.h"
00009 #include "ibrdtn/api/Client.h"
00010 #include "ibrdtn/api/FileBundle.h"
00011 #include "ibrcommon/net/tcpclient.h"
00012 #include "ibrcommon/thread/Mutex.h"
00013 #include "ibrcommon/thread/MutexLock.h"
00014
00015 #include <iostream>
00016
00017 void print_help()
00018 {
00019 cout << "-- dtnsend (IBR-DTN) --" << endl;
00020 cout << "Syntax: dtnsend [options] <dst> <filename>" << endl;
00021 cout << " <dst> set the destination eid (e.g. dtn://node/filetransfer)" << endl;
00022 cout << " <filename> the file to transfer" << endl;
00023 cout << "* optional parameters *" << endl;
00024 cout << " -h|--help display this text" << endl;
00025 cout << " --src <name> set the source application name (e.g. filetransfer)" << endl;
00026 cout << " --lifetime <seconds> set the lifetime of outgoing bundles; default: 3600" << endl;
00027
00028 }
00029
00030 int main(int argc, char *argv[])
00031 {
00032 string file_destination = "dtn://local/filetransfer";
00033 string file_source = "filetransfer";
00034 unsigned int lifetime = 3600;
00035
00036 if (argc == 1)
00037 {
00038 print_help();
00039 return 0;
00040 }
00041
00042 for (int i = 0; i < argc; i++)
00043 {
00044 string arg = argv[i];
00045
00046
00047 if (arg == "-h" || arg == "--help")
00048 {
00049 print_help();
00050 return 0;
00051 }
00052
00053 if (arg == "--src" && argc > i)
00054 {
00055 file_source = argv[i + 1];
00056 }
00057
00058 if (arg == "--lifetime" && argc > i)
00059 {
00060 stringstream data; data << argv[i + 1];
00061 data >> lifetime;
00062 }
00063 }
00064
00065
00066 file_destination = argv[argc - 2];
00067
00068
00069 string filename = argv[argc -1];
00070
00071 try {
00072
00073 ibrcommon::tcpclient conn("127.0.0.1", 4550);
00074
00075 try {
00076
00077 dtn::api::Client client(dtn::api::Client::MODE_SENDONLY, file_source, conn);
00078
00079
00080
00081 client.connect();
00082
00083
00084 EID addr = EID(file_destination);
00085
00086 cout << "Transfer file \"" << filename << "\" to " << addr.getNodeEID() << endl;
00087
00088 try {
00089
00090 dtn::api::FileBundle b(file_destination, filename);
00091
00092
00093 b.setLifetime(lifetime);
00094
00095
00096 client << b;
00097
00098
00099 client.flush();
00100 } catch (ibrcommon::IOException ex) {
00101 std::cerr << "Error while sending bundle." << std::endl;
00102 std::cerr << "\t" << ex.what() << std::endl;
00103 }
00104
00105
00106 client.close();
00107 } catch (ibrcommon::IOException ex) {
00108 cout << "Error: " << ex.what() << endl;
00109 }
00110
00111
00112 conn.close();
00113 } catch (...) {
00114
00115 }
00116
00117 return 0;
00118 }