
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Cocker, a socket module to aggressively handle connection retries.
NOTE: It directly inherits from net.Socket.
$ npm install cocker [-g]
require:
const Cocker = require( 'cocker' );
$ cd cocker/
$ npm test
to execute a single test file simply do:
$ node test/file-name.js
Arguments between [ ] are optional.
Cocker( [ Object options ] )
or
new Cocker( [ Object options ] )
NOTE: default options are listed.
It accepts a configuration hash/object:
{
, address : Object
, connection : Object
, reconnection : Object
}
{
host : '127.0.0.1'
, port : 0
, family : null
/*
* Specify an IPC endpoint, like a unix domain socket, if a string is
* provided, the TCP-specific options above are ignored.
* For further details, see "Identifying paths for IPC connections" in
* the /api/net section.
*/
, path : null
}
{
// should connect from
localAddress : undefined
, localPort: undefined
// custom lookup and hints
, lookup : dns.lookup
, hints : 0
}
{
encoding : null
, keepAlive : true
, timeout : 0
, noDelay : true
, allowHalfOpen : false
}
{
trials : 3
, interval : 1000
/*
* A value to use for calculating the pause between two
* connection attempts. Default value is the golden ratio.
* Final value is calculated as:
* interval * Math.pow( factor, curr.attempts + 1 )
*/
, factor : ( Math.sqrt( 5 ) + 1 ) / 2
}
NOTE: do not mess up with these properties.
Cocker.options : Object
Cocker.attempts : Number
Cocker.lost : Boolean
Cocker.stop : Boolean
Cocker.lapse : Number
all the methods from net.Socket module are inherited.
| name | description |
|---|---|
| bye | end the connection. |
| run | connect to a socket or attempting to. |
| die | end the connection. (Promise) |
| hunt | connect to a socket or attempting to. (Promise) |
| prey | connect using a list of hosts. (Promise) |
| watch | re-connect after losing the current connection. (Promise) |
Arguments between [ ] are optional.
end the connection (without re-connecting).
'bye' : function ( [ Buffer | String data [, String enc ] ] ) : undefined
connect to a socket or attempting to (k times).
// it optionally accepts a cocker option object to reconfigure the socket.
'run' : function ( [ Object cocker_options ] ) : undefined
end the connection (without re-connecting).
// Promise will not be resolved until 'lost' event
'die' : function ( [ Buffer | String data [, String enc ] ] ) : Promise
connect to a socket or attempting to (k times).
/*
* Try to connect to a socket. Promise will not be resolved until 'online',
* rejected after 'lost' event; it optionally accepts a cocker option object
* to reconfigure the socket.
*/
'hunt' : function ( [ Object cocker_options ] ) : Promise
try to connect until success, using a list of optional hosts/config.
/*
* It recursively scan a list, using #hunt Promises. The #prey Promise will
* not be resolved until a connection will be made, definitively rejected
* when no hosts had accepted one.
* Every host in the list should be an object like Cocker.options.address.
*/
'prey' : function ( Array hosts ) : Promise
try to re-connect after losing the current connection.
/*
* When the current established connection is lost, it tries to reconnect.
* This Promise has the same resolution as for #hunt, the only difference is
* that this Promise was "registered" on socket disconnection, then it will be
* resolved/rejected only after capturing a 'lost' event from the current
* broken connection. See examples.
*/
'watch' : function ( [ Object cocker_options ] ) : Promise
all the events from net.Socket module are inherited.
// when: soon after socket !connect event
'online' : function ( Object address )
// when: on the first !close event for the current socket
'offline' : function ( Object address )
// when: after !offline, on every connection attempt, until !lost or !online
'attempt' : function ( Number t, Object address, Number lapse )
// when: soon before the last !close event.
'lost' : function ( Number t, Object address, Number lapse )
See examples.
Copyright (c) 2013-present < Guglielmo Ferri : 44gatti@gmail.com >
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Cocker, a socket module to aggressively handle connection retries..
The npm package cocker receives a total of 20 weekly downloads. As such, cocker popularity was classified as not popular.
We found that cocker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.