added setup kvvars
This commit is contained in:
		
							parent
							
								
									5bde99967b
								
							
						
					
					
						commit
						6f1daf50d3
					
				
					 3 changed files with 50 additions and 27 deletions
				
			
		|  | @ -23,9 +23,8 @@ from communicatorutils import announcenode, deniableinserts | |||
| from communicatorutils import cooldownpeer | ||||
| from communicatorutils import housekeeping | ||||
| from communicatorutils import netcheck | ||||
| from onionrutils import epoch | ||||
| from onionrthreads import add_onionr_thread | ||||
| from onionrcommands.openwebinterface import get_url | ||||
| from etc import humanreadabletime | ||||
| import onionrservices | ||||
| from netcontroller import NetController | ||||
| from . import bootstrappeers | ||||
|  | @ -61,22 +60,6 @@ class OnionrCommunicatorDaemon: | |||
| 
 | ||||
|         # populate kv values | ||||
|         self.kv = self.shared_state.get_by_string('DeadSimpleKV') | ||||
|         self.kv.put('blockQueue', {}) | ||||
|         self.kv.put('shutdown', False) | ||||
|         self.kv.put('onlinePeers', []) | ||||
|         self.kv.put('offlinePeers', []) | ||||
|         self.kv.put('peerProfiles', []) | ||||
|         self.kv.put('connectTimes', {}) | ||||
|         self.kv.put('currentDownloading', []) | ||||
|         self.kv.put('announceCache', {}) | ||||
|         self.kv.put('newPeers', []) | ||||
|         self.kv.put('dbTimestamps', {}) | ||||
|         self.kv.put('blocksToUpload', []) | ||||
|         self.kv.put('cooldownPeer', {}) | ||||
|         self.kv.put('generating_blocks', []) | ||||
|         self.kv.put('lastNodeSeen', None) | ||||
|         self.kv.put('startTime', epoch.get_epoch()) | ||||
|         self.kv.put('isOnline', True) | ||||
| 
 | ||||
|         if config.get('general.offline_mode', False): | ||||
|             self.kv.put('isOnline', False) | ||||
|  | @ -103,8 +86,6 @@ class OnionrCommunicatorDaemon: | |||
|         # extends our upload list and saves our list when Onionr exits | ||||
|         uploadqueue.UploadQueue(self) | ||||
| 
 | ||||
|         if developmentMode: | ||||
|             OnionrCommunicatorTimers(self, self.heartbeat, 30) | ||||
| 
 | ||||
|         # Set timers, function reference, seconds | ||||
|         # requires_peer True means the timer function won't fire if we | ||||
|  | @ -302,13 +283,6 @@ class OnionrCommunicatorDaemon: | |||
|             self.kv.get('peerProfiles').append(retData) | ||||
|         return retData | ||||
| 
 | ||||
|     def heartbeat(self): | ||||
|         """Show a heartbeat debug message.""" | ||||
|         logger.debug('Heartbeat. Node running for %s.' % | ||||
|                      humanreadabletime.human_readable_time( | ||||
|                          self.kv.get('startTime'))) | ||||
|         self.decrementThreadCount('heartbeat') | ||||
| 
 | ||||
| 
 | ||||
| def startCommunicator(shared_state): | ||||
|     OnionrCommunicatorDaemon(shared_state) | ||||
|  |  | |||
|  | @ -39,6 +39,7 @@ from lan import LANManager | |||
| from lan.server import LANServer | ||||
| from sneakernet import sneakernet_import_thread | ||||
| from onionrstatistics.devreporting import statistics_reporter | ||||
| from setupkvvars import setup_kv | ||||
| """ | ||||
|     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 | ||||
|  | @ -135,6 +136,9 @@ def daemon(): | |||
|     # Add DeadSimpleKV for quasi-global variables (ephemeral key-value) | ||||
|     shared_state.get(DeadSimpleKV) | ||||
| 
 | ||||
|     # Initialize the quasi-global variables | ||||
|     setup_kv(shared_state.get(DeadSimpleKV)) | ||||
| 
 | ||||
|     shared_state.get(daemoneventsapi.DaemonEventsBP) | ||||
| 
 | ||||
|     Thread(target=shared_state.get(apiservers.ClientAPI).start, | ||||
|  |  | |||
							
								
								
									
										45
									
								
								src/setupkvvars/__init__.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								src/setupkvvars/__init__.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | |||
| """Onionr - Private P2P Communication. | ||||
| 
 | ||||
| Initialize singleton deadsimplekv pseudo globals | ||||
| """ | ||||
| 
 | ||||
| from typing import TYPE_CHECKING | ||||
| 
 | ||||
| from onionrutils import epoch | ||||
| 
 | ||||
| if TYPE_CHECKING: | ||||
|     from deadsimplekv import DeadSimpleKV | ||||
| """ | ||||
|     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 <https://www.gnu.org/licenses/>. | ||||
| """ | ||||
| 
 | ||||
| 
 | ||||
| def setup_kv(shared_vars: 'DeadSimpleKV'): | ||||
|     """Init initial pseudo-variables.""" | ||||
|     shared_vars.put('blockQueue', {}) | ||||
|     shared_vars.put('shutdown', False) | ||||
|     shared_vars.put('onlinePeers', []) | ||||
|     shared_vars.put('offlinePeers', []) | ||||
|     shared_vars.put('peerProfiles', []) | ||||
|     shared_vars.put('connectTimes', {}) | ||||
|     shared_vars.put('currentDownloading', []) | ||||
|     shared_vars.put('announceCache', {}) | ||||
|     shared_vars.put('newPeers', []) | ||||
|     shared_vars.put('dbTimestamps', {}) | ||||
|     shared_vars.put('blocksToUpload', []) | ||||
|     shared_vars.put('cooldownPeer', {}) | ||||
|     shared_vars.put('generating_blocks', []) | ||||
|     shared_vars.put('lastNodeSeen', None) | ||||
|     shared_vars.put('startTime', epoch.get_epoch()) | ||||
|     shared_vars.put('isOnline', True) | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue