- 
                Notifications
    You must be signed in to change notification settings 
- Fork 505
feat: configuration validation #2133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Draft
      
      
            achingbrain
  wants to merge
  25
  commits into
  main
  
    
      
        
          
  
    
      Choose a base branch
      
     
    
      
        
      
      
        
          
          
        
        
          
            
              
              
              
  
           
        
        
          
            
              
              
           
        
       
     
  
        
          
            
          
            
          
        
       
    
      
from
feat/config-validation
  
      
      
   
  
    
  
  
  
 
  
      
    base: main
Could not load branches
            
              
  
    Branch not found: {{ refName }}
  
            
                
      Loading
              
            Could not load tags
            
            
              Nothing to show
            
              
  
            
                
      Loading
              
            Are you sure you want to change the base?
            Some commits from the old base branch may be removed from the timeline,
            and old review comments may become outdated.
          
          
      
        
          +396
        
        
          −166
        
        
          
        
      
    
  
  
     Draft
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            25 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      0f394b3
              
                feat: configuration validation (#1778)
              
              
                maschad e8f3158
              
                Merge branch 'master' into feat/config-validation
              
              
                maschad 80fd92e
              
                refactor: updated functions according to pr comments
              
              
                maschad 5ccd6bf
              
                chore: ensure inboundConnectionThreshold is a number
              
              
                maschad 94e089b
              
                Merge branch 'master' into feat/config-validation
              
              
                achingbrain 4ece976
              
                refactor: address PR comments
              
              
                maschad 78a2c4a
              
                chore: refactor variable name from pr feedback
              
              
                maschad e3046d8
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad cba7c2f
              
                refactor: updated config validation
              
              
                maschad 7f38cdc
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad 355824d
              
                deps: add yup as dep
              
              
                maschad 6ef1271
              
                chore: fix identify issue
              
              
                maschad e836612
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad e25bdb8
              
                fix: remove max parallel dials per peer param
              
              
                maschad 9ff9ad9
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad cf3dd84
              
                fix: update transport with config
              
              
                maschad 1770c3d
              
                feat: add config validation to perf service
              
              
                maschad f8e3193
              
                fix: update config to sort addresses properly
              
              
                maschad fd3a1b1
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad 94e19d8
              
                fix: fixes related to PR feedback
              
              
                maschad d1c1f25
              
                fix: update error + transport imports
              
              
                maschad c63c235
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad ce55e11
              
                Merge branch 'main' into feat/config-validation
              
              
                maschad 1eb436e
              
                adjust imports
              
              
                maschad 1b072f4
              
                Merge remote-tracking branch 'origin/main' into feat/config-validation
              
              
                achingbrain File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              This file was deleted.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { FaultTolerance } from '@libp2p/interface' | ||
| import { defaultAddressSort } from '@libp2p/utils/address-sort' | ||
| import { dnsaddrResolver } from '@multiformats/multiaddr/resolvers' | ||
| import mergeOptions from 'merge-options' | ||
| import { object } from 'yup' | ||
| import { validateAddressManagerConfig } from '../address-manager/utils.js' | ||
| import { validateConnectionManagerConfig } from '../connection-manager/utils.js' | ||
| import type { ConnectionManagerInit } from '../connection-manager/index.js' | ||
| import type { Libp2pInit } from '../index.js' | ||
| import type { ServiceMap, RecursivePartial } from '@libp2p/interface' | ||
|  | ||
| const defaultConfig: Partial<Libp2pInit> = { | ||
| connectionManager: { | ||
| resolvers: { | ||
| dnsaddr: dnsaddrResolver | ||
| }, | ||
| addressSorter: defaultAddressSort | ||
| }, | ||
| transportManager: { | ||
| faultTolerance: FaultTolerance.FATAL_ALL | ||
| } | ||
| } | ||
|  | ||
| export function validateConfig<T extends ServiceMap = Record<string, unknown>> (opts: RecursivePartial<Libp2pInit<T>>): Libp2pInit<T> { | ||
| const libp2pConfig = object({ | ||
| addresses: validateAddressManagerConfig(), | ||
| connectionManager: validateConnectionManagerConfig(opts?.connectionManager as ConnectionManagerInit) | ||
| }) | ||
|  | ||
| const parsedOpts = libp2pConfig.validateSync(opts) | ||
|  | ||
| const resultingOptions: Libp2pInit<T> = mergeOptions(defaultConfig, parsedOpts) | ||
|  | ||
| return resultingOptions | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { CodeError } from '@libp2p/interface' | ||
| import { multiaddr } from '@multiformats/multiaddr' | ||
| import { codes } from '../errors.js' | ||
|  | ||
| export const validateMultiaddr = (value: Array<string | undefined> | undefined): boolean => { | ||
| if (value == null || value === undefined) { | ||
| return false | ||
| } | ||
|  | ||
| value?.forEach((addr) => { | ||
| try { | ||
| multiaddr(addr) | ||
| } catch (err) { | ||
| throw new CodeError(`invalid multiaddr: ${addr}`, codes.ERR_INVALID_MULTIADDR) | ||
| } | ||
| }) | ||
|  | ||
| return true | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#rpc-messages | ||
| export const MAX_DCUTR_MESSAGE_SIZE = 1024 * 4 | ||
| // ensure the dial has a high priority to jump to the head of the dial queue | ||
| export const DCUTR_DIAL_PRIORITY = 100 | ||
|  | ||
| export const DEFAULT_MAX_INBOUND_STREAMS = 1 | ||
|  | ||
| export const DEFAULT_MAX_OUTBOUND_STREAMS = 1 | ||
|  | ||
| export const DEFAULT_TIMEOUT = 5000 | ||
|  | ||
| export const DEFAULT_RETRIES = 3 | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| // https://github.com/libp2p/specs/tree/master/fetch#wire-protocol | ||
| export const PROTOCOL_VERSION = '0.0.1' | ||
| export const PROTOCOL_NAME = 'fetch' | ||
|  | ||
| export const MAX_INBOUND_STREAMS = 1 | ||
| export const MAX_OUTBOUND_STREAMS = 1 | ||
| export const TIMEOUT = 10000 | ||
| export const PROTOCOL_PREFIX = 'libp2p' | 
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.