Skip to content

Commit

Permalink
Added daemon basic API class and basic and incomplete 'service' classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
GamePad64 committed Jan 2, 2014
1 parent a1e6531 commit df9768f
Show file tree
Hide file tree
Showing 9 changed files with 312 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/daemon/api/APIService.cpp
@@ -0,0 +1,29 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "APIService.h"

namespace p2pnet {
namespace api {

APIService::APIService() {
// TODO Auto-generated constructor stub

}

APIService::~APIService() {
// TODO Auto-generated destructor stub
}

} /* namespace api */
} /* namespace p2pnet */
29 changes: 29 additions & 0 deletions src/daemon/api/APIService.h
@@ -0,0 +1,29 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef APISERVICE_H_
#define APISERVICE_H_

namespace p2pnet {
namespace api {

class APIService {
public:
APIService();
virtual ~APIService();
};

} /* namespace api */
} /* namespace p2pnet */

#endif /* APISERVICE_H_ */
36 changes: 36 additions & 0 deletions src/daemon/service/LocalService.cpp
@@ -0,0 +1,36 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LocalService.h"

namespace p2pnet {
namespace service {

LocalService::LocalService(service_type type) {
this->type = type;
this->api_service_ptr = nullptr;
}

LocalService::LocalService(service_type type, api::APIService* api_service_ptr) {
this->type = type;
this->api_service_ptr = api_service_ptr;
}

LocalService::~LocalService() {}

SH LocalService::getSH() const {
return SH(private_key.derivePublicKey());
}

} /* namespace service */
} /* namespace p2pnet */
53 changes: 53 additions & 0 deletions src/daemon/service/LocalService.h
@@ -0,0 +1,53 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef LOCALSERVICE_H_
#define LOCALSERVICE_H_

#include "../../common/crypto/PrivateKeyDSA.h"
#include "SH.h"

namespace p2pnet {

namespace api {
class APIService;
}

namespace service {

class LocalService {
protected:
api::APIService* api_service_ptr;

enum service_type {
STANDARD = 0,
//BROADCAST = 1
} type;

crypto::PrivateKeyDSA private_key; //TODO use system-wide cryptographic storage.
std::set<std::string> namespaces;
public:
LocalService(service_type type);
LocalService(service_type type, api::APIService* api_service_ptr);
virtual ~LocalService();

SH getSH() const;

virtual void send(SH dest, std::string data) = 0;
virtual void process(SH from, std::string data) = 0;
};

} /* namespace service */
} /* namespace p2pnet */

#endif /* LOCALSERVICE_H_ */
28 changes: 28 additions & 0 deletions src/daemon/service/SH.h
@@ -0,0 +1,28 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef SH_H_
#define SH_H_

#include "../../common/crypto/Hash.h"

namespace p2pnet {
namespace service {

typedef crypto::Hash SH;

} /* namespace service */
} /* namespace p2pnet */

#endif /* SH_H_ */
29 changes: 29 additions & 0 deletions src/daemon/service/ServiceManager.cpp
@@ -0,0 +1,29 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ServiceManager.h"

namespace p2pnet {
namespace service {

ServiceManager::ServiceManager() {
// TODO Auto-generated constructor stub

}

ServiceManager::~ServiceManager() {
// TODO Auto-generated destructor stub
}

} /* namespace service */
} /* namespace p2pnet */
47 changes: 47 additions & 0 deletions src/daemon/service/ServiceManager.h
@@ -0,0 +1,47 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SERVICEMANAGER_H_
#define SERVICEMANAGER_H_

#include <map>
#include <list>
#include <memory>

namespace p2pnet {

namespace api {
class APIService;
}

namespace service {

class LocalService;

class ServiceManager {
std::map<api::APIService*, std::shared_ptr<LocalService>> api_services;
std::list<std::shared_ptr<LocalService>> system_services;

std::map<SH, std::shared_ptr<LocalService>> services_sh;
public:
ServiceManager();
virtual ~ServiceManager();

void registerAPIService(api::APIService* api_service);
void removeAPIService(api::APIService* api_service);
};

} /* namespace service */
} /* namespace p2pnet */

#endif /* SERVICEMANAGER_H_ */
29 changes: 29 additions & 0 deletions src/daemon/service/StandardService.cpp
@@ -0,0 +1,29 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "StandardService.h"

namespace p2pnet {
namespace service {

StandardService::StandardService() : LocalService(STANDARD) {
}

StandardService::StandardService(api::APIService* api_service_ptr) : LocalService(STANDARD, api_service_ptr) {
}

StandardService::~StandardService() {
}

} /* namespace service */
} /* namespace p2pnet */
32 changes: 32 additions & 0 deletions src/daemon/service/StandardService.h
@@ -0,0 +1,32 @@
/*
* You may redistribute this program and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation,
* either version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef STANDARDSERVICE_H_
#define STANDARDSERVICE_H_

#include "LocalService.h"

namespace p2pnet {
namespace service {

class StandardService : public p2pnet::service::LocalService {
public:
StandardService();
StandardService(api::APIService* api_service_ptr);
virtual ~StandardService();
};

} /* namespace service */
} /* namespace p2pnet */

#endif /* STANDARDSERVICE_H_ */

0 comments on commit df9768f

Please sign in to comment.