aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-11 10:51:53 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-12-11 10:51:53 +0100
commit17309629889269e99d14b4e880675682d8b6435f (patch)
treeab37c07e186315410d0187b52c4d5b5492555662
parent7797c8fb5fa69068dd659c369bc774ca74f592fe (diff)
downloadlibnitrokey-17309629889269e99d14b4e880675682d8b6435f.tar.gz
libnitrokey-17309629889269e99d14b4e880675682d8b6435f.tar.bz2
Allow to execute client-supplied function on each retry and cancel with itwip-retry_function
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
-rw-r--r--NitrokeyManager.cc6
m---------hidapi0
-rw-r--r--include/NitrokeyManager.h2
-rw-r--r--include/device_proto.h5
-rw-r--r--unittest/conftest.py7
5 files changed, 16 insertions, 4 deletions
diff --git a/NitrokeyManager.cc b/NitrokeyManager.cc
index b29b27d..6c3634e 100644
--- a/NitrokeyManager.cc
+++ b/NitrokeyManager.cc
@@ -12,6 +12,8 @@
std::mutex nitrokey::proto::send_receive_mtx;
+nitrokey::proto::retry_type nitrokey::proto::on_retry = [](int){return 0;};
+
namespace nitrokey{
std::mutex mex_dev_com_manager;
@@ -61,6 +63,10 @@ using nitrokey::misc::strcpyT;
NitrokeyManager::~NitrokeyManager() {
}
+ void NitrokeyManager::set_retry_function(const nitrokey::proto::retry_type retry_func){
+ nitrokey::proto::on_retry = retry_func;
+ }
+
bool NitrokeyManager::set_current_device_speed(int retry_delay, int send_receive_delay){
if (retry_delay < 20 || send_receive_delay < 20){
LOG("Delay set too low: " + to_string(retry_delay) +" "+ to_string(send_receive_delay), Loglevel::WARNING);
diff --git a/hidapi b/hidapi
-Subproject b767b43f3e6f9c5b92ea7d738331deb8e03c4ba
+Subproject b24dd9c36c4aacfd5ba7b1f0277d98bbbee43f1
diff --git a/include/NitrokeyManager.h b/include/NitrokeyManager.h
index de14fbc..e4842c2 100644
--- a/include/NitrokeyManager.h
+++ b/include/NitrokeyManager.h
@@ -179,8 +179,8 @@ char * strndup(const char* str, size_t maxlen);
public:
bool set_current_device_speed(int retry_delay, int send_receive_delay);
void set_loglevel(Loglevel loglevel);
-
void set_loglevel(int loglevel);
+ void set_retry_function(const retry_type retry_func);
};
}
diff --git a/include/device_proto.h b/include/device_proto.h
index 388c721..89fed12 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -1,6 +1,7 @@
#ifndef DEVICE_PROTO_H
#define DEVICE_PROTO_H
+#include <functional>
#include <utility>
#include <thread>
#include <type_traits>
@@ -38,6 +39,8 @@
namespace nitrokey {
namespace proto {
extern std::mutex send_receive_mtx;
+ using retry_type = std::function <int(int)>;
+ extern retry_type on_retry;
/*
@@ -362,6 +365,8 @@ namespace nitrokey {
dev->m_counters.total_retries++;
LOG(".", Loglevel::DEBUG_L1);
std::this_thread::sleep_for(retry_timeout);
+ if (on_retry(receiving_retry_counter) == -1)
+ throw DeviceReceivingFailure("User canceled");
continue;
}
if (successful_communication) break;
diff --git a/unittest/conftest.py b/unittest/conftest.py
index a53b005..d54a362 100644
--- a/unittest/conftest.py
+++ b/unittest/conftest.py
@@ -56,7 +56,8 @@ def C(request):
print("No library file found")
sys.exit(1)
- C.NK_set_debug(False)
+ C.NK_set_debug(True)
+ C.NK_set_debug_level(4)
nk_login = C.NK_login_auto()
if nk_login != 1:
print('No devices detected!')
@@ -77,7 +78,7 @@ def C(request):
print('Finished')
request.addfinalizer(fin)
- # C.NK_set_debug(True)
- C.NK_set_debug_level(3)
+ C.NK_set_debug(True)
+ C.NK_set_debug_level(4)
return C