def _serverSetup(self): # Create a server factory, get a protocol from it, connect it to a # transport, and return all three. wrappedFactory = protocol.ServerFactory() wrappedFactory.protocol = SimpleProtocol factory = policies.TimeoutFactory(wrappedFactory, 3) proto = factory.buildProtocol(address.IPv4Address('TCP', '127.0.0.1', 12345)) transport = StringTransportWithDisconnection() transport.protocol = proto proto.makeConnection(transport) return factory, proto, transport
self._reArm() with self.lock: delete = [] for start, end in self.rules: rule = self.rules[(start, end)] if self.database.expire(start, end): delete.append((start, end)) for start, end in delete: self.table.delete_rule(option['chain'], rule) del self.rules[(start, end)] print 'expired rule %s/%d' % (toips(start), tobits(end - start + 1)) # Starting ... from twisted.application import internet, service from twisted.protocols import policies application = service.Application('action-netfilter') serviceCollection = service.IServiceCollection(application) factory = policies.TimeoutFactory(MailFactory(), timeoutPeriod=option.timeout) internet.TCPServer(option.port, factory).setServiceParent(serviceCollection) serviceCollection.startService() reactor.run() sys.exit(1)
from twisted.internet import protocol, reactor from twisted.protocols import policies from scavenger.policy.service import MailPolicyService, PluginError from scavenger.policy.factory import IMailPolicyFactory from scavenger.policy.configuration import Configuration, ConfigurationError configuration = Configuration(option.configuration) configuration.display() reactor.suggestThreadPoolSize(configuration['thread']) application = service.Application('mail policy', uid=1, gid=1) serviceCollection = service.IServiceCollection(application) try: mailservice = MailPolicyService(configuration) except PluginError: print 'no plugin match the criteria given, can not start the policy server' sys.exit(1) mailfactory = policies.TimeoutFactory(IMailPolicyFactory(mailservice), timeoutPeriod=configuration['timeout']) internet.TCPServer(configuration['port'], mailfactory).setServiceParent(serviceCollection) serviceCollection.startService() reactor.run() sys.exit(1)
data = self.subjects.get(ip, []) if data: return '214-' + prefix + prefix.join(data) else: return '214-' + prefix + '[no data available]' def body(self, ip): prefix = '\r\n214-BODY %s\r\n' % ip with self.lock: data = self.bodies.get(ip, []) if data: return '214-' + ('-' * 76) + prefix + prefix.join(data) else: return '214-' + ('-' * 76) + prefix + '214-[no data available]' application = service.Application('mta-spam') serviceCollection = service.IServiceCollection(application) factory = policies.TimeoutFactory(MailFactory(option.sampling_subject, option.nb_subject, option.sampling_body, option.nb_body, option.max_size_body), timeoutPeriod=option.timeout) internet.TCPServer(option.port, factory).setServiceParent(serviceCollection) serviceCollection.startService() reactor.run() sys.exit(1)