Skip to content

Commit

Permalink
Added update_secure_channel_port to update the port used for creating…
Browse files Browse the repository at this point in the history
… secure channels
  • Loading branch information
TheoPierne committed Oct 21, 2022
1 parent 47edcfc commit c73cfa0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions bosdyn-client/robot.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Robot {
this.authorities_by_name = {};
this._robot_id = null;
this._has_arm = null;
this._secure_channel_port = _DEFAULT_SECURE_CHANNEL_PORT;

// Things usually updated from an Sdk object.
this.service_client_factories_by_type = {};
Expand Down Expand Up @@ -266,30 +267,29 @@ class Robot {
}));
const channelData = channel.create_secure_channel(
this.address,
_DEFAULT_SECURE_CHANNEL_PORT,
this._secure_channel_port,
creds,
authority,
options,
);
this.logger.debug(
`[ROBOT] Created channel to ${this.address} at port ${_DEFAULT_SECURE_CHANNEL_PORT} with authority ${authority}`,
`[ROBOT] Created channel to ${this.address} at port ${this._secure_channel_port} with authority ${authority}`,
);
this.channels_by_authority[authority] = channelData;
return channelData;
}

ensure_insecure_channel(authority, options = []) {
if (authority in this.channels_by_authority) return this.channels_by_authority[authority];
const channelData = channel.create_insecure_channel(this.address, _DEFAULT_SECURE_CHANNEL_PORT, authority, options);
const channelData = channel.create_insecure_channel(this.address, this._secure_channel_port, authority, options);
this.logger.warn(
`[ROBOT] Created insecure channel to ${this.address} at port ${_DEFAULT_SECURE_CHANNEL_PORT} with authority ${authority}`,
`[ROBOT] Created insecure channel to ${this.address} at port ${this._secure_channel_port} with authority ${authority}`,
);
this.channels_by_authority[authority] = channelData;
return channelData;
}

async authenticate(username, password, timeout) {
console.log('Pensez à modifier authenticate dans le fichier robot.js');
const default_service_name = AuthClient.default_service_name;
const auth_channel = this.ensure_secure_channel(this._bootstrap_service_authorities[default_service_name]);
const auth_client = await this.ensure_client(default_service_name, auth_channel);
Expand Down Expand Up @@ -344,9 +344,9 @@ class Robot {

get_cached_usernames() {
const matches = this.token_cache.match(this.serial_number);
let usernames = [];
const usernames = [];
for (const match of matches) {
let username = match.split('.');
const username = match.split('.');
usernames.push(username);
}
return usernames.sort();
Expand Down Expand Up @@ -489,6 +489,10 @@ class Robot {
this._has_arm = has_arm(state_client, timeout);
return this._has_arm;
}

update_secure_channel_port(secure_channel_port) {
this._secure_channel_port = secure_channel_port;
}
}

module.exports = {
Expand Down

0 comments on commit c73cfa0

Please sign in to comment.