Example #1
0
 def _available_transports(self):
     from main import settings
     atransports = []
     if settings.enableTCP() and settings.enableTCPreceiving() and settings.enableTCPsending():
         atransports.append('service_tcp_transport')
     if settings.enableUDP() and settings.enableUDPreceiving() and settings.enableUDPsending():
         atransports.append('service_udp_transport')
     return atransports
 def _available_transports(self):
     from main import settings
     atransports = []
     if settings.enableTCP() and settings.enableTCPreceiving(
     ) and settings.enableTCPsending():
         atransports.append('service_tcp_transport')
     if settings.enableUDP() and settings.enableUDPreceiving(
     ) and settings.enableUDPsending():
         atransports.append('service_udp_transport')
     return atransports
Example #3
0
 def _push(self):
     from transport import gateway
     if self.route:
         # if this packet is routed - send directly to route host
         gateway.send_file(
             strng.to_bin(self.route['remoteid']),
             strng.to_text(self.route['proto']),
             strng.to_bin(self.route['host']),
             self.filename,
             self.description,
             self,
         )
         self.items.append(
             WorkItem(strng.to_text(self.route['proto']),
                      strng.to_bin(self.route['host']), self.filesize))
         self.automat('items-sent')
         return
     # get info about his local IP
     localIP = identitycache.GetLocalIP(self.remote_idurl)
     workitem_sent = False
     if self.wide:
         # send to all his contacts
         for contactmethod in self.remote_identity.getContacts():
             proto, host = nameurl.IdContactSplit(contactmethod)
             if host.strip() and \
                     settings.transportIsEnabled(proto) and \
                     settings.transportSendingIsEnabled(proto) and \
                     gateway.can_send(proto) and \
                     gateway.is_installed(proto):
                 if proto == 'tcp' and localIP:
                     host = localIP
                 gateway.send_file(
                     strng.to_bin(self.remote_idurl),
                     strng.to_text(proto),
                     strng.to_bin(host),
                     self.filename,
                     self.description,
                     self,
                 )
                 self.items.append(
                     WorkItem(strng.to_text(proto), strng.to_bin(host),
                              self.filesize))
                 workitem_sent = True
         if not workitem_sent:
             self.automat('nothing-to-send')
             lg.warn('(wide) no supported protocols with %s' %
                     self.remote_idurl)
         else:
             self.automat('items-sent')
         return
     # send to one of his contacts,
     # now need to decide which transport to use
     # let's prepare his contacts first
     byproto = self.remote_identity.getContactsByProto()
     tcp_contact = None
     if settings.enableTCP() and settings.enableTCPsending():
         tcp_contact = byproto.get('tcp', None)
     udp_contact = None
     if settings.enableUDP() and settings.enableUDPsending():
         udp_contact = byproto.get('udp', None)
     http_contact = None
     if settings.enableHTTP() and settings.enableHTTPsending():
         http_contact = byproto.get('http', None)
     proxy_contact = None
     if settings.enablePROXY() and settings.enablePROXYsending():
         proxy_contact = byproto.get('proxy', None)
     working_protos = p2p_stats.peers_protos().get(self.remote_idurl, set())
     # tcp seems to be the most stable proto
     # now let's check if we know his local IP and
     # he enabled tcp in his settings to be able to receive packets from others
     # try to send to his local IP first, not external
     if tcp_contact and localIP:
         if gateway.is_installed('tcp') and gateway.can_send(proto):
             proto, host, port, fn = nameurl.UrlParse(tcp_contact)
             if port:
                 host = localIP + ':' + str(port)
             gateway.send_file(strng.to_bin(self.remote_idurl),
                               strng.to_text(proto), strng.to_bin(host),
                               self.filename, self.description, self)
             self.items.append(
                 WorkItem(strng.to_text(proto), strng.to_bin(host),
                          self.filesize))
             self.automat('items-sent')
             return
     # tcp is the best proto - if it is working - this is the best case!!!
     if tcp_contact and 'tcp' in working_protos:
         proto, host, port, fn = nameurl.UrlParse(tcp_contact)
         if host.strip() and gateway.is_installed(
                 proto) and gateway.can_send(proto):
             if port:
                 host = host + ':' + str(port)
             gateway.send_file(strng.to_bin(self.remote_idurl),
                               strng.to_text(proto), strng.to_bin(host),
                               self.filename, self.description)
             self.items.append(
                 WorkItem(strng.to_text(proto), strng.to_bin(host),
                          self.filesize))
             self.automat('items-sent')
             return
     # udp contact
     if udp_contact and 'udp' in working_protos:
         proto, host = nameurl.IdContactSplit(udp_contact)
         if host.strip() and gateway.is_installed(
                 'udp') and gateway.can_send(proto):
             gateway.send_file(strng.to_bin(self.remote_idurl),
                               strng.to_text(proto), strng.to_bin(host),
                               self.filename, self.description, self)
             self.items.append(
                 WorkItem(strng.to_text(proto), strng.to_bin(host),
                          self.filesize))
             self.automat('items-sent')
             return
     # http contact
     if http_contact and 'http' in working_protos:
         proto, host, port, _ = nameurl.UrlParse(http_contact)
         if host.strip() and gateway.is_installed(
                 proto) and gateway.can_send(proto):
             if port:
                 host = host + ':' + str(port)
             gateway.send_file(strng.to_bin(self.remote_idurl),
                               strng.to_text(proto), strng.to_bin(host),
                               self.filename, self.description, self)
             self.items.append(
                 WorkItem(strng.to_text(proto), strng.to_bin(host),
                          self.filesize))
             self.automat('items-sent')
             return
     # proxy contact - he may use other node to receive and send packets
     if proxy_contact and 'proxy' in working_protos:
         proto, host = nameurl.IdContactSplit(proxy_contact)
         if host.strip() and gateway.is_installed(
                 'proxy') and gateway.can_send(proto):
             gateway.send_file(strng.to_bin(self.remote_idurl),
                               strng.to_text(proto), strng.to_bin(host),
                               self.filename, self.description, self)
             self.items.append(
                 WorkItem(strng.to_text(proto), strng.to_bin(host),
                          self.filesize))
             self.automat('items-sent')
             return
     # finally use the first proto we supported if we can not find the best preferable method
     for contactmethod in self.remote_identity.getContacts():
         proto, host, port, fn = nameurl.UrlParse(contactmethod)
         if port:
             host = host + ':' + str(port)
         # if method exist but empty - don't use it
         if host.strip():
             # try sending with tcp even if it is switched off in the settings
             if gateway.is_installed(proto) and gateway.can_send(proto):
                 if settings.enableTransport(
                         proto) and settings.transportSendingIsEnabled(
                             proto):
                     gateway.send_file(strng.to_bin(self.remote_idurl),
                                       strng.to_text(proto),
                                       strng.to_bin(host), self.filename,
                                       self.description, self)
                     self.items.append(
                         WorkItem(strng.to_text(proto), strng.to_bin(host),
                                  self.filesize))
                     self.automat('items-sent')
                     return
     self.automat('nothing-to-send')
     lg.warn('no supported protocols with %s : %s %s %s, byproto:%s' %
             (self.remote_idurl, tcp_contact, udp_contact, working_protos,
              str(byproto)))
Example #4
0
 def _push(self):
     if self.route:
         # if this packet is routed - send directly to route host
         gateway.send_file(
             self.route["remoteid"], self.route["proto"], self.route["host"], self.filename, self.description
         )
         self.items.append(WorkItem(self.route["proto"], self.route["host"], self.filesize))
         self.automat("items-sent")
         return
     # get info about his local IP
     localIP = identitycache.GetLocalIP(self.remote_idurl)
     workitem_sent = False
     if self.wide:
         # send to all his contacts
         for contactmethod in self.remote_identity.getContacts():
             proto, host = nameurl.IdContactSplit(contactmethod)
             if (
                 host.strip()
                 and settings.transportIsEnabled(proto)
                 and settings.transportSendingIsEnabled(proto)
                 and gateway.can_send(proto)
                 and gateway.is_installed(proto)
             ):
                 if proto == "tcp" and localIP:
                     host = localIP
                 gateway.send_file(self.remote_idurl, proto, host, self.filename, self.description)
                 self.items.append(WorkItem(proto, host, self.filesize))
                 workitem_sent = True
         if not workitem_sent:
             self.automat("nothing-to-send")
             lg.warn("(wide) no supported protocols with %s" % self.remote_idurl)
         else:
             self.automat("items-sent")
         return
     # send to one of his contacts,
     # now need to decide which transport to use
     # let's prepare his contacts first
     byproto = self.remote_identity.getContactsByProto()
     tcp_contact = None
     if settings.enableTCP() and settings.enableTCPsending():
         tcp_contact = byproto.get("tcp", None)
     udp_contact = None
     if settings.enableUDP() and settings.enableUDPsending():
         udp_contact = byproto.get("udp", None)
     proxy_contact = None
     if settings.enablePROXY() and settings.enablePROXYsending():
         proxy_contact = byproto.get("proxy", None)
     working_protos = stats.peers_protos().get(self.remote_idurl, set())
     # tcp seems to be the most stable proto
     # now let's check if we know his local IP and
     # he enabled tcp in his settings to be able to receive packets from others
     # try to send to his local IP first, not external
     if tcp_contact and localIP:
         if gateway.is_installed("tcp") and gateway.can_send(proto):
             proto, host, port, fn = nameurl.UrlParse(tcp_contact)
             if port:
                 host = localIP + ":" + str(port)
             gateway.send_file(self.remote_idurl, proto, host, self.filename, self.description)
             self.items.append(WorkItem(proto, host, self.filesize))
             self.automat("items-sent")
             return
     # tcp is the best proto - if it is working - this is the best case!!!
     if tcp_contact and "tcp" in working_protos:
         proto, host, port, fn = nameurl.UrlParse(tcp_contact)
         if host.strip() and gateway.is_installed(proto) and gateway.can_send(proto):
             if port:
                 host = host + ":" + str(port)
             gateway.send_file(self.remote_idurl, proto, host, self.filename, self.description)
             self.items.append(WorkItem(proto, host, self.filesize))
             self.automat("items-sent")
             return
     # udp contact
     if udp_contact and "udp" in working_protos:
         proto, host = nameurl.IdContactSplit(udp_contact)
         if host.strip() and gateway.is_installed("udp") and gateway.can_send(proto):
             gateway.send_file(self.remote_idurl, proto, host, self.filename, self.description)
             self.items.append(WorkItem(proto, host, self.filesize))
             self.automat("items-sent")
             return
     # proxy contact - he may use other node to receive and send packets
     if proxy_contact and "proxy" in working_protos:
         proto, host = nameurl.IdContactSplit(proxy_contact)
         if host.strip() and gateway.is_installed("proxy") and gateway.can_send(proto):
             gateway.send_file(self.remote_idurl, proto, host, self.filename, self.description)
             self.items.append(WorkItem(proto, host, self.filesize))
             self.automat("items-sent")
             return
     # finally use the first proto we supported if we can not find the best preferable method
     for contactmethod in self.remote_identity.getContacts():
         proto, host, port, fn = nameurl.UrlParse(contactmethod)
         if port:
             host = host + ":" + str(port)
         # if method exist but empty - don't use it
         if host.strip():
             # try sending with tcp even if it is switched off in the settings
             if gateway.is_installed(proto) and gateway.can_send(proto):
                 if settings.enableTransport(proto) and settings.transportSendingIsEnabled(proto):
                     gateway.send_file(self.remote_idurl, proto, host, self.filename, self.description)
                     self.items.append(WorkItem(proto, host, self.filesize))
                     self.automat("items-sent")
                     return
     self.automat("nothing-to-send")
     lg.warn(
         "no supported protocols with %s : %s %s %s, byproto:%s"
         % (self.remote_idurl, tcp_contact, udp_contact, working_protos, str(byproto))
     )