aboutsummaryrefslogtreecommitdiffstats
path: root/apps/producers
diff options
context:
space:
mode:
authorMauro Sardara <msardara+fdio@cisco.com>2017-02-22 14:37:37 +0100
committerMauro Sardara <msardara+fdio@cisco.com>2017-02-22 13:46:08 +0000
commitba8541cad3a4069886444abbd1848b6ef3fff72c (patch)
tree39226dd9b036ca7e513c2cccd8e71e15e09b86bc /apps/producers
parent9b30fc10fb1cbebe651e5a107e8ca5b24de54675 (diff)
Initial Commit: libicnet
Change-Id: I10a72cb0d84b76553a85c168416b847f6a4ff5f6 Signed-off-by: Mauro Sardara <msardara+fdio@cisco.com>
Diffstat (limited to 'apps/producers')
-rwxr-xr-xapps/producers/CMakeLists.txt22
-rwxr-xr-xapps/producers/icnet_producer_test.cc163
2 files changed, 185 insertions, 0 deletions
diff --git a/apps/producers/CMakeLists.txt b/apps/producers/CMakeLists.txt
new file mode 100755
index 00000000..c478bf53
--- /dev/null
+++ b/apps/producers/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright (c) 2017 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.2)
+
+
+set(PRODUCER_SOURCE_FILES
+ icnet_producer_test.cc)
+
+add_executable(producer-test ${PRODUCER_SOURCE_FILES})
+target_link_libraries(producer-test icnet ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES})
+install(TARGETS producer-test DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
diff --git a/apps/producers/icnet_producer_test.cc b/apps/producers/icnet_producer_test.cc
new file mode 100755
index 00000000..571e9615
--- /dev/null
+++ b/apps/producers/icnet_producer_test.cc
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2017 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "icnet_socket_producer.h"
+
+#define IDENTITY_NAME "ciao"
+
+namespace icnet {
+
+class CallbackContainer {
+ public:
+ CallbackContainer() : buffer_(1400, 'X') {
+ content_object_.setContent((uint8_t *) buffer_.c_str(), 1400);
+ }
+
+ void processInterest(ProducerSocket &p, const Interest &interest) {
+ // std::cout << "Sending response to " << interest.getName() << std::endl;
+ }
+
+ void processIncomingInterest(ProducerSocket &p, const Interest &interest) {
+ content_object_.setName(Name(interest.getName().getWrappedStructure()));
+ p.produce(content_object_);
+ }
+ private:
+
+ ContentObject content_object_;
+ std::string buffer_;
+};
+
+class Signer {
+ public:
+ Signer() : counter_(0), identity_name_(IDENTITY_NAME) {
+ };
+
+ ~Signer() {
+ };
+
+ void onPacket(ProducerSocket &p, ContentObject &contentObject) {
+ counter_++;
+ KeyLocator kl;
+ contentObject.signWithSha256(kl);
+ }
+
+ private:
+ int counter_;
+ Name identity_name_;
+};
+
+void becomeDaemon() {
+ pid_t process_id = 0;
+ pid_t sid = 0;
+
+ // Create child process
+ process_id = fork();
+
+ // Indication of fork() failure
+ if (process_id < 0) {
+ printf("fork failed!\n");
+ // Return failure in exit status
+ exit(EXIT_FAILURE);
+ }
+
+ // PARENT PROCESS. Need to kill it.
+ if (process_id > 0) {
+ printf("process_id of child process %d \n", process_id);
+ // return success in exit status
+ exit(EXIT_SUCCESS);
+ }
+
+ //unmask the file mode
+ umask(0);
+
+ //set new session
+ sid = setsid();
+ if (sid < 0) {
+ // Return failure
+ exit(EXIT_FAILURE);
+ }
+
+ // Change the current working directory to root.
+ chdir("/");
+
+ // Close stdin. stdout and stderr
+ close(STDIN_FILENO);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+
+ // Really start application
+}
+
+int main(int argc, char **argv) {
+ std::string name = "ccnx:/ccnxtest";
+ bool daemon = false;
+
+ int opt;
+ while ((opt = getopt(argc, argv, "D")) != -1) {
+
+ switch (opt) {
+ case 'D':
+ daemon = true;
+ break;
+ default:
+ exit(EXIT_FAILURE);
+ }
+ }
+
+ if (argv[optind] == 0) {
+ std::cerr << "Using default name ccnx:/ccnxtest" << std::endl;
+ } else {
+ name = argv[optind];
+ }
+
+ if (daemon) {
+ becomeDaemon();
+ }
+
+ CallbackContainer stubs;
+ // Signer signer;
+
+ std::cout << "Setting name.. " << name << std::endl;
+
+ ProducerSocket p(Name(name.c_str()));
+
+ p.setSocketOption(GeneralTransportOptions::MAKE_MANIFEST, false);
+
+ // setting callbacks
+ p.setSocketOption(ProducerCallbacksOptions::INTEREST_INPUT,
+ (ProducerInterestCallback) bind(&CallbackContainer::processIncomingInterest,
+ &stubs,
+ std::placeholders::_1,
+ std::placeholders::_2));
+
+ p.setSocketOption(ProducerCallbacksOptions::CACHE_MISS,
+ (ProducerInterestCallback) bind(&CallbackContainer::processInterest,
+ &stubs,
+ std::placeholders::_1,
+ std::placeholders::_2));
+
+ p.attach();
+
+ p.serveForever();
+
+ return 0;
+}
+
+} // end namespace icnet
+
+int main(int argc, char **argv) {
+ return icnet::main(argc, argv);
+}
+