Skip to content

Commit

Permalink
Merge 1a3fceb into d5a60b6
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Oct 18, 2022
2 parents d5a60b6 + 1a3fceb commit 034eb6d
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 120 deletions.
4 changes: 2 additions & 2 deletions lib/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ class CoAPServer extends EventEmitter {
return (msg: Buffer, rsinfo: AddressInfo) => {
const request: MiddlewareParameters = {
raw: msg,
rsinfo: rsinfo,
rsinfo,
server: this
}
const activeMiddlewares: Function[] = []
Expand All @@ -210,7 +210,7 @@ class CoAPServer extends EventEmitter {
_sendError (payload: Buffer, rsinfo: AddressInfo, packet?: CoapPacket, code = '5.00'): void {
const message = generate({
code,
payload: payload,
payload,
messageId: packet != null ? packet.messageId : undefined,
token: packet != null ? packet.token : undefined
})
Expand Down
2 changes: 1 addition & 1 deletion models/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import CoAPServer from '../lib/server'
export declare function requestListener (req: IncomingMessage, res: OutgoingMessage): void

export type OptionValue = null | string | number | Buffer | Buffer[]
export type BlockCacheMap<T> = Map<string, {payload: T, timeoutId: NodeJS.Timeout}>
export type BlockCacheMap<T> = Map<string, { payload: T, timeoutId: NodeJS.Timeout }>
export type CoapOptions = Partial<Record<OptionName, OptionValue>>

export interface Option {
Expand Down
26 changes: 13 additions & 13 deletions test/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ describe('Agent', function () {

it('should discard the request after receiving the payload for piggyback CON requests with observe request', function (done) {
const req = request({
port: port,
agent: agent,
port,
agent,
observe: true,
confirmable: true
}).end()
Expand All @@ -419,7 +419,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: false,
ack: true,
rsinfo: rsinfo
rsinfo
})

// duplicate, as there was some retransmission
Expand All @@ -429,7 +429,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: false,
ack: true,
rsinfo: rsinfo
rsinfo
})

// some more data
Expand All @@ -438,7 +438,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: true,
ack: false,
rsinfo: rsinfo
rsinfo
})
})

Expand All @@ -452,8 +452,8 @@ describe('Agent', function () {
let firstRsinfo: AddressInfo

const req = request({
port: port,
agent: agent,
port,
agent,
observe: true,
confirmable: true
}).end()
Expand All @@ -467,7 +467,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: false,
ack: true,
rsinfo: rsinfo
rsinfo
})
})

Expand All @@ -489,8 +489,8 @@ describe('Agent', function () {

it('should allow observe with non-confirmable requests', function (done) {
const req = request({
port: port,
agent: agent,
port,
agent,
observe: true,
confirmable: false
}).end()
Expand All @@ -506,7 +506,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: false,
ack: false,
rsinfo: rsinfo
rsinfo
})

// duplicate, as there was some retransmission
Expand All @@ -516,7 +516,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: false,
ack: false,
rsinfo: rsinfo
rsinfo
})

// some more data
Expand All @@ -525,7 +525,7 @@ describe('Agent', function () {
token: packet.token,
confirmable: false,
ack: false,
rsinfo: rsinfo
rsinfo
})
})

Expand Down
18 changes: 9 additions & 9 deletions test/blockwise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('blockwise2', function () {
const payload = Buffer.alloc(100) // default max packet is 1280

request({
port: port
port
})
.on('response', (res) => {
let blockwiseResponse = false
Expand All @@ -84,7 +84,7 @@ describe('blockwise2', function () {

it('should use blockwise in response when payload bigger than max packet', function (done) {
request({
port: port
port
})
.on('response', (res) => {
let blockwiseResponse = false
Expand All @@ -106,7 +106,7 @@ describe('blockwise2', function () {

it('should blockwise response have etag', function (done) {
request({
port: port
port
})
.on('response', (res) => {
expect(typeof res.headers.ETag).to.eql('string')
Expand All @@ -121,7 +121,7 @@ describe('blockwise2', function () {

it('should accept early negotation', function (done) {
request({
port: port
port
})
.setOption('Block2', Buffer.of(0x02))
.on('response', (res) => {
Expand All @@ -145,7 +145,7 @@ describe('blockwise2', function () {

it('should receive error when early negotation request block size higher than 1024', function (done) {
request({
port: port
port
})
.setOption('Block2', Buffer.of(0x07)) // request for block 0, with overload size of 2**(7+4)
.on('response', (res) => {
Expand All @@ -164,7 +164,7 @@ describe('blockwise2', function () {
// blocks are requested with a zero based index, i.e. indices 0, 1 and 2
// block index 3 or higher is "out of range" and should cause an error response
request({
port: port
port
})
.setOption('Block2', Buffer.of(0x3D)) // request for block index 3
.on('response', (res) => {
Expand All @@ -180,7 +180,7 @@ describe('blockwise2', function () {

it('should be able to receive part of message', function (done) {
request({
port: port
port
})
.setOption('Block2', Buffer.of(0x10)) // request from block 1, with size = 16
.on('response', (res) => {
Expand All @@ -197,7 +197,7 @@ describe('blockwise2', function () {
it('should receive full response payload', function (done) {
const payload = Buffer.alloc(16 * 0xff + 1)
request({
port: port
port
})
.setOption('Block2', Buffer.of(0x0)) // early negotation with block size = 16, almost 10000/16 = 63 blocks
.on('response', (res) => {
Expand Down Expand Up @@ -232,7 +232,7 @@ describe('blockwise2', function () {
let req2Done = false
let req1Block2Num = 0
const reqClient2 = request({
port: port
port
})

fillPayloadBuffer(payloadReq1)
Expand Down
16 changes: 8 additions & 8 deletions test/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('Cache', () => {

describe('Reset', () => {
it('Should reset all caches', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
b.reset()
expect(b._cache.size).to.eql(0)
Expand All @@ -30,7 +30,7 @@ describe('Cache', () => {

describe('Add', () => {
it('Should add to cache', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
expect(b.contains('test')).to.equal(true)
setImmediate(done)
Expand All @@ -40,7 +40,7 @@ describe('Cache', () => {

describe('Remove', () => {
it('Should from cache', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
b.add('test2', { payload: 'test2' })
b.remove('test')
Expand All @@ -51,14 +51,14 @@ describe('Cache', () => {

describe('Contains', () => {
it('Should check if value exists & return true', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
expect(b.contains('test')).to.eql(true)
setImmediate(done)
})

it('Should check if value exists & return false', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
expect(b.contains('test2')).to.eql(false)
setImmediate(done)
Expand All @@ -67,7 +67,7 @@ describe('Cache', () => {

describe('Get', () => {
it('Should return payload from cache', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
expect(b.get('test')).to.eql({ payload: 'test' })
setImmediate(done)
Expand All @@ -76,14 +76,14 @@ describe('Cache', () => {

describe('Get with default insert', () => {
it('Should return payload from cache if it exists', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.add('test', { payload: 'test' })
expect(b.getWithDefaultInsert('test')).to.eql({ payload: 'test' })
setImmediate(done)
})

it('Should add to cache if it doesnt exist', (done) => {
const b = new BlockCache<{payload: string} | null>(10000, () => { return null })
const b = new BlockCache<{ payload: string } | null>(10000, () => { return null })
b.getWithDefaultInsert('test')
expect(b.contains('test')).to.equal(true)
setImmediate(done)
Expand Down

0 comments on commit 034eb6d

Please sign in to comment.