Let the session own its bind state, written by bound() alone #42

Merged
lilleman merged 11 commits from session-bound into main 2026-09-28 04:37:29 +02:00
4 changed files with 33 additions and 5 deletions
Showing only changes of commit ebc5db5a00 - Show all commits
+1 -1
View File
@@ -62,6 +62,6 @@ describe('smppload (blocked)', () => {
await waitFor(() => (closed ? true : undefined), 5000);
assert.equal(closed, true);
assert.ok(bound);
assert.equal(bound.loggedIn, false);
assert.equal(bound.boundAs, undefined);
});
});
+8 -2
View File
@@ -628,6 +628,10 @@ describe('reconnect', () => {
const reconnected = once<true>(resolve => { session.on('reconnected', () => { resolve(true); }); });
const halfPdu = once<true>(resolve => { session.on('data', () => { resolve(true); }); });
const boundBefore = [session.boundAs, session.peerInterfaceVersion];
const whileDown = once<unknown[]>(resolve => {
session.on('disconnected', () => { resolve([session.boundAs, session.peerInterfaceVersion]); });
});
// A PDU header promising 32 octets and sending 8: the next link must not continue it.
peerOf(smpp).sock.write(Buffer.from([0, 0, 0, 32, 0, 0, 0, 4]));
@@ -640,7 +644,9 @@ describe('reconnect', () => {
await reconnected;
assert.ok(session.loggedIn);
// The loop rebinds as before, so the gap keeps answering bindAllows() for the bind to come.
assert.deepEqual(await whileDown, boundBefore);
assert.equal(session.boundAs, 'transceiver');
// The session object survives the drop, so listeners stay attached and it is usable again.
const sent = await session.sendSms({
@@ -867,7 +873,7 @@ describe('reconnect from the first bind', () => {
assert.equal(err, undefined);
assert.ok(session);
assert.equal(session.loggedIn, true);
assert.equal(session.boundAs, 'transceiver');
assert.ok(spy.delays.length >= 3, 'the SMSC was down for several attempts');
assert.deepEqual(spy.delays.slice(0, 3), [10, 20, 40], 'each wait doubles, up to maxDelay');
assert.ok(
+23 -1
View File
@@ -229,7 +229,7 @@ describe('bind', () => {
assert.equal(err, undefined);
assert.ok(session);
assert.ok(session.loggedIn);
assert.equal(session.boundAs, 'transceiver');
assert.deepEqual(await session.unbind(), {});
});
@@ -448,6 +448,28 @@ describe('bind', () => {
assert.ok(session.acceptsOptionalParams());
});
test('records a hand-wired bind through bound(), and nothing else writes it', t => {
const session = new Session({ sock: new net.Socket() });
closeAfter(t, session);
assert.equal(session.boundAs, undefined);
assert.equal(session.peerInterfaceVersion, undefined);
session.bound('receiver', 0x34);
assert.equal(session.boundAs, 'receiver');
assert.equal(session.peerInterfaceVersion, 0x34);
assert.equal(session.bindAllows('submit_sm'), false);
session.bound('transmitter', undefined);
assert.equal(session.peerInterfaceVersion, 0x00, 'no declared version is pre-3.4');
assert.equal(Reflect.set(session, 'boundAs', 'transceiver'), false);
assert.equal(Reflect.set(session, 'peerInterfaceVersion', 0x50), false);
assert.equal(session.boundAs, 'transmitter');
assert.equal('loggedIn' in session, false);
});
// The spec: an absent sc_interface_version means the SMSC supports no optional parameters.
test('takes an SMSC that declares no version as older than 3.4', async t => {
const peer = await smscPeer(t);
+1 -1
View File
@@ -135,7 +135,7 @@ describe('tls', () => {
assert.equal(err, undefined);
assert.ok(session);
assert.ok(session.loggedIn);
assert.equal(session.boundAs, 'transceiver');
closeAfter(t, session);
const sock = session.sock;