Skip to content

Commit

Permalink
Merge branch 'main' into multitenancy
Browse files Browse the repository at this point in the history
  • Loading branch information
rsdmike authored Nov 28, 2022
2 parents 42c25a6 + 249317a commit 4c49bf0
Show file tree
Hide file tree
Showing 27 changed files with 317 additions and 120 deletions.
5 changes: 5 additions & 0 deletions .github/commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ module.exports = {
'never',
['sentence-case', 'start-case', 'pascal-case', 'upper-case'],
],
'scope-enum': [
2,
'always',
['db', 'api', 'secrets', 'cira', 'apf', 'health', 'utils', 'redir', 'events', 'docker', 'deps', 'deps-dev', 'gh-actions', 'config']
]
}
}
14 changes: 0 additions & 14 deletions .github/semantic.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/api-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- run: docker build -f Dockerfile -t mps:${GITHUB_SHA} .
- run: docker-compose up -d
- run: sleep 30
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: docker run -v $PWD:/workdir quay.io/git-chglog/git-chglog --next-tag $(node --eval="process.stdout.write(require('./package.json').version)") --output CHANGELOG.md
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v3

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build the Docker image

run: docker build . --file Dockerfile --tag vprodemo.azurecr.io/mps:${{ github.sha }} --tag vprodemo.azurecr.io/mps:latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Build the Docker image

run: docker build . --file Dockerfile --tag ${{ github.event.inputs.docker_registry }}/${{ github.event.inputs.docker_tag_name }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
node-version: [14.x, 16.x, 18.x]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
Expand Down
17 changes: 8 additions & 9 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
name: "Semantic Pull Request"

on:
pull_request_target:
types:
- opened
- edited
- synchronize
pull_request:
types: ['opened', 'edited', 'reopened', 'synchronize']
jobs:
main:
name: Validate PR and Commits
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: wagoid/commitlint-github-action@v4
with:
configFile: .github/commitlint.config.js
- name: Install Dependencies
run: npm install @commitlint/config-conventional
- uses: JulienKode/[email protected]
with:
configuration-path: ./.github/commitlint.config.js
21 changes: 14 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ Must be one of the following:

Should be one of the following:
Modules:
* **common**: A change or addition to the common module
* **tracker**: A change or addition to the tracker module
* **server**: A change or addition to the server module
* **msgs**: A change or addition to msgs module
* **eval**: Any change to benchmark tools
* **deps**: A change to any dependency or 3rd-party library
* **all**: A change that affects all modules
* **apf**: A change or addition to amt port forwarding functionality
* **api**: A change or addition to REST functionality
* **cira**: A change or addition to client initiated remote access functionality
* **config**: A change or addition to service configuration
* **db**: A change or addition to database calls or functionality
* **deps**: A change or addition to dependencies (primarily used by dependabot)
* **deps-dev**: A change or addition to developer dependencies (primarily used by dependabot)
* **docker**: A change or addition to docker file or composition
* **events**: A change or addition to eventing from the service
* **gh-actions**: A change or addition to GitHub actions
* **health**: A change or addition to health checks
* **redir**: A change or addition to redirection functionality
* **secrets**: A change or addition to secret store calls or functionality
* **utils**: A change or addition to the utility functions
* *no scope*: If no scope is provided, it is assumed the PR does not apply to the above scopes

### Body
Expand Down
25 changes: 18 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"bottleneck": "^2.19.5",
"consul": "^1.1.0",
"cors": "^2.8.5",
"exponential-backoff": "^3.1.0",
"express": "^4.18.2",
"express-validator": "^6.14.2",
"got": "^11.8.5",
Expand All @@ -56,7 +57,7 @@
"@types/express": "^4.17.14",
"@types/jest": "^27.4.1",
"@types/node": "^16.11.15",
"@types/node-forge": "^1.3.0",
"@types/node-forge": "^1.3.1",
"@types/pg": "^8.6.5",
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^4.33.0",
Expand All @@ -76,4 +77,4 @@
"ts-node": "^10.9.1",
"typescript": "^4.8.4"
}
}
}
26 changes: 14 additions & 12 deletions src/amt/APFProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

import { Buffer } from 'node:buffer'
import Common from '../utils/common'
import { logger } from '../logging'
import APFProcessor, { APFProtocol } from './APFProcessor'
Expand Down Expand Up @@ -259,9 +260,7 @@ describe('APFProcessor Tests', () => {

it('should return 9 if sending entire pending buffer', () => {
const fakeCiraChannel: CIRAChannel = {
sendBuffer: {
length: 1000
},
sendBuffer: Buffer.alloc(1000),
sendcredits: 1000,
socket: {
write: jest.fn()
Expand All @@ -287,7 +286,7 @@ describe('APFProcessor Tests', () => {

it('should return 9 if sending partial pending buffer', () => {
const fakeCiraChannel: CIRAChannel = {
sendBuffer: 'my fake buffer',
sendBuffer: Buffer.from('my fake buffer'),
sendcredits: 5,
socket: {
write: jest.fn()
Expand Down Expand Up @@ -461,7 +460,7 @@ describe('APFProcessor Tests', () => {
const length = 17
const data = ''
fakeCiraChannel.closing = 0
fakeCiraChannel.sendBuffer = 'fake buffer'
fakeCiraChannel.sendBuffer = Buffer.from('fake buffer')
fakeCiraChannel.onStateChange = new EventEmitter()
const result = APFProcessor.channelOpenConfirmation(fakeCiraSocket, length, data)
expect(result).toEqual(17)
Expand All @@ -475,7 +474,7 @@ describe('APFProcessor Tests', () => {
const data = ''
const readIntSpy = jest.spyOn(Common, 'ReadInt').mockReturnValue(1)
fakeCiraChannel.closing = 0
fakeCiraChannel.sendBuffer = 'fake buffer'
fakeCiraChannel.sendBuffer = Buffer.from('fake buffer')
fakeCiraChannel.onStateChange = new EventEmitter()
const result = APFProcessor.channelOpenConfirmation(fakeCiraSocket, length, data)
expect(result).toEqual(17)
Expand Down Expand Up @@ -1139,13 +1138,16 @@ describe('APFProcessor Tests', () => {
})

it('should SendChannelData', () => {
APFProcessor.SendChannelData(fakeCiraSocket, channelid, data)
const dataExpected =
writeSpy = jest.spyOn(fakeCiraSocket, 'write')
APFProcessor.SendChannelData(fakeCiraSocket, channelid, Buffer.from(data))
const dataExpected = Buffer.from(
String.fromCharCode(APFProtocol.CHANNEL_DATA) +
Common.IntToStr(channelid) +
Common.IntToStr(data.length) +
data
expect(writeSpy).toHaveBeenCalledWith(fakeCiraSocket, dataExpected)
Common.IntToStr(channelid) +
Common.IntToStr(data.length) +
data,
'binary'
)
expect(writeSpy).toHaveBeenCalledWith(dataExpected)
})

it('should SendChannelWindowAdjust', () => {
Expand Down
57 changes: 30 additions & 27 deletions src/amt/APFProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* SPDX-License-Identifier: Apache-2.0
**********************************************************************/

import { Buffer } from 'node:buffer'
import { logger, messages } from '../logging'
import Common from '../utils/common'
import { CIRASocket } from '../models/models'
import { CIRAChannel } from './CIRAChannel'
import { EventEmitter } from 'stream'
const KEEPALIVE_INTERVAL = 30 // 30 seconds is typical keepalive interval for AMT CIRA connection

Expand Down Expand Up @@ -155,19 +157,8 @@ const APFProcessor = {
}
cirachannel.sendcredits += ByteToAdd
logger.silly(`${messages.MPS_WINDOW_ADJUST}, ${RecipientChannel.toString()}, ${ByteToAdd.toString()}, ${cirachannel.sendcredits}`)
if (cirachannel.state === 2 && cirachannel.sendBuffer != null) {
// Compute how much data we can send
if (cirachannel.sendBuffer.length <= cirachannel.sendcredits) {
// Send the entire pending buffer
APFProcessor.SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer)
cirachannel.sendcredits -= cirachannel.sendBuffer.length
delete cirachannel.sendBuffer
} else {
// Send a part of the pending buffer
APFProcessor.SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.substring(0, cirachannel.sendcredits))
cirachannel.sendBuffer = cirachannel.sendBuffer.substring(cirachannel.sendcredits)
cirachannel.sendcredits = 0
}
if (cirachannel.state === 2) {
APFProcessor.SendPendingData(cirachannel)
}
return 9
},
Expand Down Expand Up @@ -232,19 +223,7 @@ const APFProcessor = {
} else {
cirachannel.state = 2
// Send any pending data
if (cirachannel.sendBuffer != null) {
if (cirachannel.sendBuffer.length <= cirachannel.sendcredits) {
// Send the entire pending buffer
APFProcessor.SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer)
cirachannel.sendcredits -= cirachannel.sendBuffer.length
delete cirachannel.sendBuffer
} else {
// Send a part of the pending buffer
APFProcessor.SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.substring(0, cirachannel.sendcredits))
cirachannel.sendBuffer = cirachannel.sendBuffer.substring(cirachannel.sendcredits)
cirachannel.sendcredits = 0
}
}
APFProcessor.SendPendingData(cirachannel)
// Indicate the channel is open
if (cirachannel.onStateChange) {
cirachannel.onStateChange.emit('stateChange', cirachannel.state)
Expand Down Expand Up @@ -535,15 +514,39 @@ const APFProcessor = {
APFProcessor.Write(socket, String.fromCharCode(APFProtocol.CHANNEL_CLOSE) + Common.IntToStr(channelid))
},

SendChannelData: (socket: CIRASocket, channelid, data): void => {
SendPendingData: (cirachannel: CIRAChannel): void => {
if (cirachannel.sendBuffer != null) {
if (cirachannel.sendBuffer.length <= cirachannel.sendcredits) {
// Send the entire pending buffer
APFProcessor.SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer)
cirachannel.sendcredits -= cirachannel.sendBuffer.length
delete cirachannel.sendBuffer
} else {
// Send a part of the pending buffer
APFProcessor.SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.subarray(0, cirachannel.sendcredits))
cirachannel.sendBuffer = cirachannel.sendBuffer.subarray(cirachannel.sendcredits)
cirachannel.sendcredits = 0
}
}
},

SendChannelData: (socket: CIRASocket, channelid, data: Buffer): void => {
logger.silly(`${messages.MPS_SEND_CHANNEL_DATA}, ${channelid}`)
const b = Buffer.allocUnsafe(9 + data.length)
b[0] = APFProtocol.CHANNEL_DATA
b.writeUInt32BE(channelid, 1)
b.writeUInt32BE(data.length, 5)
data.copy(b, 9)
socket.write(b)
/*
APFProcessor.Write(
socket,
String.fromCharCode(APFProtocol.CHANNEL_DATA) +
Common.IntToStr(channelid) +
Common.IntToStr(data.length) +
data
)
*/
},

SendChannelWindowAdjust: (socket: CIRASocket, channelid, bytestoadd): void => {
Expand Down
Loading

0 comments on commit 4c49bf0

Please sign in to comment.