Skip to content

Commit

Permalink
[python] Add the switch to disable server interactions (#22393)
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored and pull[bot] committed Oct 25, 2022
1 parent e03068a commit 1024600
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
8 changes: 5 additions & 3 deletions src/controller/python/ChipDeviceController-ScriptBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ chip::NodeId kDefaultLocalDeviceId = chip::kTestControllerNodeId;
chip::NodeId kRemoteDeviceId = chip::kTestDeviceNodeId;

extern "C" {
ChipError::StorageType pychip_DeviceController_StackInit(Controller::Python::StorageAdapter * storageAdapter);
ChipError::StorageType pychip_DeviceController_StackInit(Controller::Python::StorageAdapter * storageAdapter,
bool enableServerInteractions);
ChipError::StorageType pychip_DeviceController_StackShutdown();

ChipError::StorageType pychip_DeviceController_NewDeviceController(chip::Controller::DeviceCommissioner ** outDevCtrl,
Expand Down Expand Up @@ -228,7 +229,8 @@ void pychip_Storage_ShutdownAdapter(chip::Controller::Python::StorageAdapter * s
delete storageAdapter;
}

ChipError::StorageType pychip_DeviceController_StackInit(Controller::Python::StorageAdapter * storageAdapter)
ChipError::StorageType pychip_DeviceController_StackInit(Controller::Python::StorageAdapter * storageAdapter,
bool enableServerInteractions)
{
VerifyOrDie(storageAdapter != nullptr);

Expand All @@ -243,7 +245,7 @@ ChipError::StorageType pychip_DeviceController_StackInit(Controller::Python::Sto
ReturnErrorOnFailure(sPersistentStorageOpCertStore.Init(storageAdapter).AsInteger());
factoryParams.opCertStore = &sPersistentStorageOpCertStore;

factoryParams.enableServerInteractions = true;
factoryParams.enableServerInteractions = enableServerInteractions;

// Hack needed due to the fact that DnsSd server uses the CommissionableDataProvider even
// when never starting commissionable advertising. This will not be used but prevents
Expand Down
5 changes: 3 additions & 2 deletions src/controller/python/OpCredsBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,8 @@ ChipError::StorageType pychip_OpCreds_AllocateController(OpCredsContext * contex
chip::Controller::DeviceCommissioner ** outDevCtrl, FabricId fabricId,
chip::NodeId nodeId, chip::VendorId adminVendorId,
const char * paaTrustStorePath, bool useTestCommissioner,
CASEAuthTag * caseAuthTags, uint32_t caseAuthTagLen)
bool enableServerInteractions, CASEAuthTag * caseAuthTags,
uint32_t caseAuthTagLen)
{
ChipLogDetail(Controller, "Creating New Device Controller");

Expand Down Expand Up @@ -381,7 +382,7 @@ ChipError::StorageType pychip_OpCreds_AllocateController(OpCredsContext * contex
initParams.controllerRCAC = rcacSpan;
initParams.controllerICAC = icacSpan;
initParams.controllerNOC = nocSpan;
initParams.enableServerInteractions = true;
initParams.enableServerInteractions = enableServerInteractions;
initParams.controllerVendorId = adminVendorId;
initParams.permitMultiControllerFabrics = true;

Expand Down
5 changes: 3 additions & 2 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,13 @@ def __init__(self, opCredsContext: ctypes.c_void_p, fabricId: int, nodeId: int,
c_catTags[i] = item

self._dmLib.pychip_OpCreds_AllocateController.argtypes = [c_void_p, POINTER(
c_void_p), c_uint64, c_uint64, c_uint16, c_char_p, c_bool, POINTER(c_uint32), c_uint32]
c_void_p), c_uint64, c_uint64, c_uint16, c_char_p, c_bool, c_bool, POINTER(c_uint32), c_uint32]
self._dmLib.pychip_OpCreds_AllocateController.restype = c_uint32

# TODO(erjiaqing@): Figure out how to control enableServerInteractions for a single device controller (node)
res = self._ChipStack.Call(
lambda: self._dmLib.pychip_OpCreds_AllocateController(c_void_p(
opCredsContext), pointer(devCtrl), fabricId, nodeId, adminVendorId, c_char_p(None if len(paaTrustStorePath) == 0 else str.encode(paaTrustStorePath)), useTestCommissioner, c_catTags, len(catTags))
opCredsContext), pointer(devCtrl), fabricId, nodeId, adminVendorId, c_char_p(None if len(paaTrustStorePath) == 0 else str.encode(paaTrustStorePath)), useTestCommissioner, self._ChipStack.enableServerInteractions, c_catTags, len(catTags))
)

if res != 0:
Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/ChipReplStartup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def mattersetdebug(enableDebugMode: bool = True):
chip.native.Init()

ReplInit(args.debug)
chipStack = ChipStack(persistentStoragePath=args.storagepath)
chipStack = ChipStack(persistentStoragePath=args.storagepath, enableServerInteractions=False)
certificateAuthorityManager = chip.CertificateAuthority.CertificateAuthorityManager(chipStack, chipStack.GetStorageManager())

certificateAuthorityManager.LoadAuthoritiesFromStorage()
Expand Down
12 changes: 9 additions & 3 deletions src/controller/python/chip/ChipStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def Wait(self, timeoutMs: int = None):

@_singleton
class ChipStack(object):
def __init__(self, persistentStoragePath: str, installDefaultLogHandler=True, bluetoothAdapter=None):
def __init__(self, persistentStoragePath: str, installDefaultLogHandler=True, bluetoothAdapter=None, enableServerInteractions=True):
builtins.enableDebugMode = False

self.networkLock = Lock()
Expand All @@ -190,6 +190,7 @@ def __init__(self, persistentStoragePath: str, installDefaultLogHandler=True, bl
self.commissioningEventRes = None
self._activeLogFunct = None
self.addModulePrefixToLogMessage = True
self._enableServerInteractions = enableServerInteractions

#
# Locate and load the chip shared library.
Expand Down Expand Up @@ -266,7 +267,8 @@ def HandleChipThreadRun(callback):
self._persistentStorage = PersistentStorage(persistentStoragePath)

# Initialize the chip stack.
res = self._ChipStackLib.pychip_DeviceController_StackInit(self._persistentStorage.GetSdkStorageObject())
res = self._ChipStackLib.pychip_DeviceController_StackInit(
self._persistentStorage.GetSdkStorageObject(), enableServerInteractions)
if res != 0:
raise self.ErrorToException(res)

Expand All @@ -279,6 +281,10 @@ def HandleChipThreadRun(callback):
def GetStorageManager(self):
return self._persistentStorage

@property
def enableServerInteractions(self):
return self._enableServerInteractions

@property
def defaultLogFunct(self):
"""Returns a python callable which, when called, logs a message to the python logger object
Expand Down Expand Up @@ -440,7 +446,7 @@ def _loadLib(self):
self._ChipStackLib = chip.native.GetLibraryHandle()
self._chipDLLPath = chip.native.FindNativeLibraryPath()

self._ChipStackLib.pychip_DeviceController_StackInit.argtypes = [c_void_p]
self._ChipStackLib.pychip_DeviceController_StackInit.argtypes = [c_void_p, c_bool]
self._ChipStackLib.pychip_DeviceController_StackInit.restype = c_uint32
self._ChipStackLib.pychip_DeviceController_StackShutdown.argtypes = []
self._ChipStackLib.pychip_DeviceController_StackShutdown.restype = c_uint32
Expand Down

0 comments on commit 1024600

Please sign in to comment.