chore(nbd-client): convert to ESM
BREAKING CHANGE
This commit is contained in:
parent
9fb749b1db
commit
7c80d0c1e1
@ -1,42 +0,0 @@
|
|||||||
'use strict'
|
|
||||||
exports.INIT_PASSWD = Buffer.from('NBDMAGIC') // "NBDMAGIC" ensure we're connected to a nbd server
|
|
||||||
exports.OPTS_MAGIC = Buffer.from('IHAVEOPT') // "IHAVEOPT" start an option block
|
|
||||||
exports.NBD_OPT_REPLY_MAGIC = 1100100111001001n // magic received during negociation
|
|
||||||
exports.NBD_OPT_EXPORT_NAME = 1
|
|
||||||
exports.NBD_OPT_ABORT = 2
|
|
||||||
exports.NBD_OPT_LIST = 3
|
|
||||||
exports.NBD_OPT_STARTTLS = 5
|
|
||||||
exports.NBD_OPT_INFO = 6
|
|
||||||
exports.NBD_OPT_GO = 7
|
|
||||||
|
|
||||||
exports.NBD_FLAG_HAS_FLAGS = 1 << 0
|
|
||||||
exports.NBD_FLAG_READ_ONLY = 1 << 1
|
|
||||||
exports.NBD_FLAG_SEND_FLUSH = 1 << 2
|
|
||||||
exports.NBD_FLAG_SEND_FUA = 1 << 3
|
|
||||||
exports.NBD_FLAG_ROTATIONAL = 1 << 4
|
|
||||||
exports.NBD_FLAG_SEND_TRIM = 1 << 5
|
|
||||||
|
|
||||||
exports.NBD_FLAG_FIXED_NEWSTYLE = 1 << 0
|
|
||||||
|
|
||||||
exports.NBD_CMD_FLAG_FUA = 1 << 0
|
|
||||||
exports.NBD_CMD_FLAG_NO_HOLE = 1 << 1
|
|
||||||
exports.NBD_CMD_FLAG_DF = 1 << 2
|
|
||||||
exports.NBD_CMD_FLAG_REQ_ONE = 1 << 3
|
|
||||||
exports.NBD_CMD_FLAG_FAST_ZERO = 1 << 4
|
|
||||||
|
|
||||||
exports.NBD_CMD_READ = 0
|
|
||||||
exports.NBD_CMD_WRITE = 1
|
|
||||||
exports.NBD_CMD_DISC = 2
|
|
||||||
exports.NBD_CMD_FLUSH = 3
|
|
||||||
exports.NBD_CMD_TRIM = 4
|
|
||||||
exports.NBD_CMD_CACHE = 5
|
|
||||||
exports.NBD_CMD_WRITE_ZEROES = 6
|
|
||||||
exports.NBD_CMD_BLOCK_STATUS = 7
|
|
||||||
exports.NBD_CMD_RESIZE = 8
|
|
||||||
|
|
||||||
exports.NBD_REQUEST_MAGIC = 0x25609513 // magic number to create a new NBD request to send to the server
|
|
||||||
exports.NBD_REPLY_MAGIC = 0x67446698 // magic number received from the server when reading response to a nbd request
|
|
||||||
exports.NBD_REPLY_ACK = 1
|
|
||||||
|
|
||||||
exports.NBD_DEFAULT_PORT = 10809
|
|
||||||
exports.NBD_DEFAULT_BLOCK_SIZE = 64 * 1024
|
|
41
@vates/nbd-client/constants.mjs
Normal file
41
@vates/nbd-client/constants.mjs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
export const INIT_PASSWD = Buffer.from('NBDMAGIC') // "NBDMAGIC" ensure we're connected to a nbd server
|
||||||
|
export const OPTS_MAGIC = Buffer.from('IHAVEOPT') // "IHAVEOPT" start an option block
|
||||||
|
export const NBD_OPT_REPLY_MAGIC = 1100100111001001n // magic received during negociation
|
||||||
|
export const NBD_OPT_EXPORT_NAME = 1
|
||||||
|
export const NBD_OPT_ABORT = 2
|
||||||
|
export const NBD_OPT_LIST = 3
|
||||||
|
export const NBD_OPT_STARTTLS = 5
|
||||||
|
export const NBD_OPT_INFO = 6
|
||||||
|
export const NBD_OPT_GO = 7
|
||||||
|
|
||||||
|
export const NBD_FLAG_HAS_FLAGS = 1 << 0
|
||||||
|
export const NBD_FLAG_READ_ONLY = 1 << 1
|
||||||
|
export const NBD_FLAG_SEND_FLUSH = 1 << 2
|
||||||
|
export const NBD_FLAG_SEND_FUA = 1 << 3
|
||||||
|
export const NBD_FLAG_ROTATIONAL = 1 << 4
|
||||||
|
export const NBD_FLAG_SEND_TRIM = 1 << 5
|
||||||
|
|
||||||
|
export const NBD_FLAG_FIXED_NEWSTYLE = 1 << 0
|
||||||
|
|
||||||
|
export const NBD_CMD_FLAG_FUA = 1 << 0
|
||||||
|
export const NBD_CMD_FLAG_NO_HOLE = 1 << 1
|
||||||
|
export const NBD_CMD_FLAG_DF = 1 << 2
|
||||||
|
export const NBD_CMD_FLAG_REQ_ONE = 1 << 3
|
||||||
|
export const NBD_CMD_FLAG_FAST_ZERO = 1 << 4
|
||||||
|
|
||||||
|
export const NBD_CMD_READ = 0
|
||||||
|
export const NBD_CMD_WRITE = 1
|
||||||
|
export const NBD_CMD_DISC = 2
|
||||||
|
export const NBD_CMD_FLUSH = 3
|
||||||
|
export const NBD_CMD_TRIM = 4
|
||||||
|
export const NBD_CMD_CACHE = 5
|
||||||
|
export const NBD_CMD_WRITE_ZEROES = 6
|
||||||
|
export const NBD_CMD_BLOCK_STATUS = 7
|
||||||
|
export const NBD_CMD_RESIZE = 8
|
||||||
|
|
||||||
|
export const NBD_REQUEST_MAGIC = 0x25609513 // magic number to create a new NBD request to send to the server
|
||||||
|
export const NBD_REPLY_MAGIC = 0x67446698 // magic number received from the server when reading response to a nbd request
|
||||||
|
export const NBD_REPLY_ACK = 1
|
||||||
|
|
||||||
|
export const NBD_DEFAULT_PORT = 10809
|
||||||
|
export const NBD_DEFAULT_BLOCK_SIZE = 64 * 1024
|
@ -1,8 +1,11 @@
|
|||||||
'use strict'
|
import assert from 'node:assert'
|
||||||
const assert = require('node:assert')
|
import { Socket } from 'node:net'
|
||||||
const { Socket } = require('node:net')
|
import { connect } from 'node:tls'
|
||||||
const { connect } = require('node:tls')
|
import { fromCallback, pRetry, pDelay, pTimeout } from 'promise-toolbox'
|
||||||
const {
|
import { readChunkStrict } from '@vates/read-chunk'
|
||||||
|
import { createLogger } from '@xen-orchestra/log'
|
||||||
|
|
||||||
|
import {
|
||||||
INIT_PASSWD,
|
INIT_PASSWD,
|
||||||
NBD_CMD_READ,
|
NBD_CMD_READ,
|
||||||
NBD_DEFAULT_BLOCK_SIZE,
|
NBD_DEFAULT_BLOCK_SIZE,
|
||||||
@ -17,16 +20,13 @@ const {
|
|||||||
NBD_REQUEST_MAGIC,
|
NBD_REQUEST_MAGIC,
|
||||||
OPTS_MAGIC,
|
OPTS_MAGIC,
|
||||||
NBD_CMD_DISC,
|
NBD_CMD_DISC,
|
||||||
} = require('./constants.js')
|
} from './constants.mjs'
|
||||||
const { fromCallback, pRetry, pDelay, pTimeout } = require('promise-toolbox')
|
|
||||||
const { readChunkStrict } = require('@vates/read-chunk')
|
|
||||||
const { createLogger } = require('@xen-orchestra/log')
|
|
||||||
|
|
||||||
const { warn } = createLogger('vates:nbd-client')
|
const { warn } = createLogger('vates:nbd-client')
|
||||||
|
|
||||||
// documentation is here : https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md
|
// documentation is here : https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md
|
||||||
|
|
||||||
module.exports = class NbdClient {
|
export default class NbdClient {
|
||||||
#serverAddress
|
#serverAddress
|
||||||
#serverCert
|
#serverCert
|
||||||
#serverPort
|
#serverPort
|
@ -17,6 +17,7 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.0"
|
"node": ">=14.0"
|
||||||
},
|
},
|
||||||
|
"main": "./index.mjs",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@vates/async-each": "^1.0.0",
|
"@vates/async-each": "^1.0.0",
|
||||||
"@vates/read-chunk": "^1.1.1",
|
"@vates/read-chunk": "^1.1.1",
|
||||||
|
@ -35,6 +35,7 @@
|
|||||||
<!--packages-start-->
|
<!--packages-start-->
|
||||||
|
|
||||||
- @vates/fuse-vhd major
|
- @vates/fuse-vhd major
|
||||||
|
- @vates/nbd-client major
|
||||||
- @xen-orchestra/backups minor
|
- @xen-orchestra/backups minor
|
||||||
- @xen-orchestra/xapi major
|
- @xen-orchestra/xapi major
|
||||||
- complex-matcher patch
|
- complex-matcher patch
|
||||||
|
Loading…
Reference in New Issue
Block a user