mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-01-30 08:04:04 +00:00
netconf service work
This commit is contained in:
parent
8d30d51cf3
commit
741642ba53
66
netconf-service/netconf-test.cpp
Normal file
66
netconf-service/netconf-test.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
/*
|
||||||
|
* ZeroTier One - Global Peer to Peer Ethernet
|
||||||
|
* Copyright (C) 2012-2013 ZeroTier Networks LLC
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it 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/>.
|
||||||
|
*
|
||||||
|
* --
|
||||||
|
*
|
||||||
|
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||||
|
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||||
|
*
|
||||||
|
* If you would like to embed ZeroTier into a commercial application or
|
||||||
|
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||||
|
* LLC. Start here: http://www.zerotier.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Self-tester that makes both new and repeated requests to netconf */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "../node/Dictionary.hpp"
|
||||||
|
#include "../node/Service.hpp"
|
||||||
|
#include "../node/Identity.hpp"
|
||||||
|
#include "../node/RuntimeEnvironment.hpp"
|
||||||
|
#include "../node/Logger.hpp"
|
||||||
|
|
||||||
|
using namespace ZeroTier;
|
||||||
|
|
||||||
|
static void svcHandler(void *arg,Service &svc,const Dictionary &msg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc,char **argv)
|
||||||
|
{
|
||||||
|
RuntimeEnvironment renv;
|
||||||
|
renv.log = new Logger((const char *)0,(const char *)0,0);
|
||||||
|
Service svc(&renv,"netconf","./netconf.service",&svcHandler,(void *)0);
|
||||||
|
|
||||||
|
srand(time(0));
|
||||||
|
|
||||||
|
std::vector<Identity> population;
|
||||||
|
for(;;) {
|
||||||
|
if ((population.empty())||(rand() < (RAND_MAX / 4))) {
|
||||||
|
} else {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -67,6 +67,7 @@
|
|||||||
#include "Mutex.hpp"
|
#include "Mutex.hpp"
|
||||||
#include "Multicaster.hpp"
|
#include "Multicaster.hpp"
|
||||||
#include "CMWC4096.hpp"
|
#include "CMWC4096.hpp"
|
||||||
|
#include "Service.hpp"
|
||||||
|
|
||||||
#include "../version.h"
|
#include "../version.h"
|
||||||
|
|
||||||
@ -191,6 +192,10 @@ struct _NodeImpl
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void _netconfServiceMessageHandler(void *renv,Service &svc,const Dictionary &msg)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
Node::Node(const char *hp)
|
Node::Node(const char *hp)
|
||||||
throw() :
|
throw() :
|
||||||
_impl(new _NodeImpl)
|
_impl(new _NodeImpl)
|
||||||
@ -209,6 +214,10 @@ Node::~Node()
|
|||||||
{
|
{
|
||||||
_NodeImpl *impl = (_NodeImpl *)_impl;
|
_NodeImpl *impl = (_NodeImpl *)_impl;
|
||||||
|
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
delete impl->renv.netconfService;
|
||||||
|
#endif
|
||||||
|
|
||||||
delete impl->renv.sysEnv;
|
delete impl->renv.sysEnv;
|
||||||
delete impl->renv.topology;
|
delete impl->renv.topology;
|
||||||
delete impl->renv.sw;
|
delete impl->renv.sw;
|
||||||
@ -337,6 +346,18 @@ Node::ReasonForTermination Node::run()
|
|||||||
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unknown exception during initialization");
|
return impl->terminateBecause(Node::NODE_UNRECOVERABLE_ERROR,"unknown exception during initialization");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
try {
|
||||||
|
std::string netconfServicePath(_r->homePath + ZT_PATH_SEPARATOR_S + "services.d" + ZT_PATH_SEPARATOR_S + "netconf.service");
|
||||||
|
if (Utils::fileExists(netconfServicePath.c_str())) {
|
||||||
|
LOG("netconf.d/netconfi.service appears to exist, starting...");
|
||||||
|
_r->netconfService = new Service(_r,"netconf",netconfServicePath.c_str(),&_netconfServiceMessageHandler,_r);
|
||||||
|
}
|
||||||
|
} catch ( ... ) {
|
||||||
|
LOG("unexpected exception attempting to start services");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
try {
|
try {
|
||||||
uint64_t lastPingCheck = 0;
|
uint64_t lastPingCheck = 0;
|
||||||
uint64_t lastClean = Utils::now(); // don't need to do this immediately
|
uint64_t lastClean = Utils::now(); // don't need to do this immediately
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#define _ZT_RUNTIMEENVIRONMENT_HPP
|
#define _ZT_RUNTIMEENVIRONMENT_HPP
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "Constants.hpp"
|
||||||
#include "Identity.hpp"
|
#include "Identity.hpp"
|
||||||
#include "Condition.hpp"
|
#include "Condition.hpp"
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ class Topology;
|
|||||||
class SysEnv;
|
class SysEnv;
|
||||||
class Multicaster;
|
class Multicaster;
|
||||||
class CMWC4096;
|
class CMWC4096;
|
||||||
|
class Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds global state for an instance of ZeroTier::Node
|
* Holds global state for an instance of ZeroTier::Node
|
||||||
@ -67,6 +69,9 @@ public:
|
|||||||
sw((Switch *)0),
|
sw((Switch *)0),
|
||||||
topology((Topology *)0),
|
topology((Topology *)0),
|
||||||
sysEnv((SysEnv *)0)
|
sysEnv((SysEnv *)0)
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
,netconfService((Service *)0)
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,6 +93,10 @@ public:
|
|||||||
Switch *sw;
|
Switch *sw;
|
||||||
Topology *topology;
|
Topology *topology;
|
||||||
SysEnv *sysEnv;
|
SysEnv *sysEnv;
|
||||||
|
|
||||||
|
#ifndef __WINDOWS__
|
||||||
|
Service *netconfService; // may be null
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZeroTier
|
} // namespace ZeroTier
|
||||||
|
@ -72,7 +72,11 @@ public:
|
|||||||
* @param handler Handler function to call when service generates output
|
* @param handler Handler function to call when service generates output
|
||||||
* @param arg First argument to service
|
* @param arg First argument to service
|
||||||
*/
|
*/
|
||||||
Service(const RuntimeEnvironment *renv,const char *name,const char *path,void (*handler)(void *,Service &,const Dictionary &),void *arg);
|
Service(const RuntimeEnvironment *renv,
|
||||||
|
const char *name,
|
||||||
|
const char *path,
|
||||||
|
void (*handler)(void *,Service &,const Dictionary &),
|
||||||
|
void *arg);
|
||||||
|
|
||||||
virtual ~Service();
|
virtual ~Service();
|
||||||
|
|
||||||
|
@ -119,6 +119,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
static uint64_t getLastModified(const char *path);
|
static uint64_t getLastModified(const char *path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param path Path to check
|
||||||
|
* @return True if file or directory exists at path location
|
||||||
|
*/
|
||||||
|
static inline bool fileExists(const char *path)
|
||||||
|
{
|
||||||
|
return (getLastModified(path) != 0);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param t64 Time in ms since epoch
|
* @param t64 Time in ms since epoch
|
||||||
* @return RFC1123 date string
|
* @return RFC1123 date string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user