mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Fix type errors and linting issues
- Fix type annotation errors in transport_registry.py and __init__.py - Fix line length violations in test files (E501 errors) - Fix missing return type annotations - Fix cryptography NameAttribute type errors with type: ignore - Fix ExceptionGroup import for cross-version compatibility - Fix test failure in test_wss_listen_without_tls_config by handling ExceptionGroup - Fix len() calls with None arguments in test_tcp_data_transfer.py - Fix missing attribute access errors on interface types - Fix boolean type expectation errors in test_js_ws_ping.py - Fix nursery context manager type errors All tests now pass and linting is clean.
This commit is contained in:
@ -13,7 +13,9 @@
|
||||
"@libp2p/ping": "^2.0.36",
|
||||
"@libp2p/websockets": "^9.2.18",
|
||||
"@chainsafe/libp2p-yamux": "^5.0.1",
|
||||
"@chainsafe/libp2p-noise": "^16.0.1",
|
||||
"@libp2p/plaintext": "^2.0.7",
|
||||
"@libp2p/identify": "^3.0.39",
|
||||
"libp2p": "^2.9.0",
|
||||
"multiaddr": "^10.0.1"
|
||||
}
|
||||
|
||||
@ -1,22 +1,76 @@
|
||||
import { createLibp2p } from 'libp2p'
|
||||
import { webSockets } from '@libp2p/websockets'
|
||||
import { ping } from '@libp2p/ping'
|
||||
import { noise } from '@chainsafe/libp2p-noise'
|
||||
import { plaintext } from '@libp2p/plaintext'
|
||||
import { yamux } from '@chainsafe/libp2p-yamux'
|
||||
// import { identify } from '@libp2p/identify' // Commented out for compatibility
|
||||
|
||||
// Configuration from environment (with defaults for compatibility)
|
||||
const TRANSPORT = process.env.transport || 'ws'
|
||||
const SECURITY = process.env.security || 'noise'
|
||||
const MUXER = process.env.muxer || 'yamux'
|
||||
const IP = process.env.ip || '0.0.0.0'
|
||||
|
||||
async function main() {
|
||||
const node = await createLibp2p({
|
||||
transports: [ webSockets() ],
|
||||
connectionEncryption: [ plaintext() ],
|
||||
streamMuxers: [ yamux() ],
|
||||
services: {
|
||||
// installs /ipfs/ping/1.0.0 handler
|
||||
ping: ping()
|
||||
console.log(`🔧 Configuration: transport=${TRANSPORT}, security=${SECURITY}, muxer=${MUXER}`)
|
||||
|
||||
// Build options following the proven pattern from test-plans-fork
|
||||
const options = {
|
||||
start: true,
|
||||
connectionGater: {
|
||||
denyDialMultiaddr: async () => false
|
||||
},
|
||||
addresses: {
|
||||
listen: ['/ip4/0.0.0.0/tcp/0/ws']
|
||||
connectionMonitor: {
|
||||
enabled: false
|
||||
},
|
||||
services: {
|
||||
ping: ping()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Transport configuration (following get-libp2p.ts pattern)
|
||||
switch (TRANSPORT) {
|
||||
case 'ws':
|
||||
options.transports = [webSockets()]
|
||||
options.addresses = {
|
||||
listen: [`/ip4/${IP}/tcp/0/ws`]
|
||||
}
|
||||
break
|
||||
case 'wss':
|
||||
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
|
||||
options.transports = [webSockets()]
|
||||
options.addresses = {
|
||||
listen: [`/ip4/${IP}/tcp/0/wss`]
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unknown transport: ${TRANSPORT}`)
|
||||
}
|
||||
|
||||
// Security configuration
|
||||
switch (SECURITY) {
|
||||
case 'noise':
|
||||
options.connectionEncryption = [noise()]
|
||||
break
|
||||
case 'plaintext':
|
||||
options.connectionEncryption = [plaintext()]
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unknown security: ${SECURITY}`)
|
||||
}
|
||||
|
||||
// Muxer configuration
|
||||
switch (MUXER) {
|
||||
case 'yamux':
|
||||
options.streamMuxers = [yamux()]
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unknown muxer: ${MUXER}`)
|
||||
}
|
||||
|
||||
console.log('🔧 Creating libp2p node with proven interop configuration...')
|
||||
const node = await createLibp2p(options)
|
||||
|
||||
await node.start()
|
||||
|
||||
@ -25,6 +79,39 @@ async function main() {
|
||||
console.log(addr.toString())
|
||||
}
|
||||
|
||||
// Debug: Print supported protocols
|
||||
console.log('DEBUG: Supported protocols:')
|
||||
if (node.services && node.services.registrar) {
|
||||
const protocols = node.services.registrar.getProtocols()
|
||||
for (const protocol of protocols) {
|
||||
console.log('DEBUG: Protocol:', protocol)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug: Print connection encryption protocols
|
||||
console.log('DEBUG: Connection encryption protocols:')
|
||||
try {
|
||||
if (node.components && node.components.connectionEncryption) {
|
||||
for (const encrypter of node.components.connectionEncryption) {
|
||||
console.log('DEBUG: Encrypter:', encrypter.protocol)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('DEBUG: Could not access connectionEncryption:', e.message)
|
||||
}
|
||||
|
||||
// Debug: Print stream muxer protocols
|
||||
console.log('DEBUG: Stream muxer protocols:')
|
||||
try {
|
||||
if (node.components && node.components.streamMuxers) {
|
||||
for (const muxer of node.components.streamMuxers) {
|
||||
console.log('DEBUG: Muxer:', muxer.protocol)
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('DEBUG: Could not access streamMuxers:', e.message)
|
||||
}
|
||||
|
||||
// Keep the process alive
|
||||
await new Promise(() => {})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user