Repository: Chia-Network/chia-blockchain
File: chia/server/server.py (Python)

Code before:
            return None
        try:
            return PeerInfo(ip, uint16(port))
        except ValueError:
            return None

    def get_port(self) -> uint16:
        if self._port is None:
            raise ValueError("Port not set")
        return uint16(self._port)

    def accept_inbound_connections(self, node_type: NodeType) -> bool:
        if not self._local_type == NodeType.FULL_NODE:
            return True
        inbound_count = len(self.get_connections(node_type, outbound=False))
        if node_type == NodeType.FULL_NODE:
            return inbound_count < cast(int, self.config.get("target_peer_count", 40)) - cast(
                int, self.config.get("target_outbound_peer_count", 8)
            )
        # For other node types than full node we try specific config keys
        # otherwise we fallback to default limits.
        key_and_limit = self.inbound_connections_info.get(node_type)
        if key_and_limit is not None:
            config_key, default_limit = key_and_limit
            limit: int = self.config.get(config_key, default_limit)
            return inbound_count < limit
        return False

    def is_trusted_peer(self, peer: WSChiaConnection, trusted_peers: dict[str, Any]) -> bool:
        return is_trusted_peer(
            host=peer.peer_info.host,
            node_id=peer.peer_node_id,
            trusted_peers=trusted_peers,
            trusted_cidrs=self.config.get("trusted_cidrs", []),
            testing=self.config.get("testing", False),
        )

    def set_capabilities(self, capabilities: list[tuple[uint16, str]]) -> None:
        self._local_capabilities_for_handshake = capabilities

    def ban_peer(self, host: str, ban_time: int) -> None:
        ban_until: float = time.time() + ban_time
        self.log.warning(f"Banning {host} for {ban_time} seconds")
        if host in self.banned_peers:
            self.banned_peers[host] = max(ban_until, self.banned_peers[host])
        else:
            self.banned_peers[host] = ban_until


Review comment (suggestion):
```suggestion
        key_and_limit = self.inbound_connections_info[node_type]
        config_key, default_limit = key_and_limit
        limit: int = self.config.get(config_key, default_limit)
        return inbound_count < limit
```

Code after:
        if node_type == NodeType.WALLET:
            return inbound_count < cast(int, self.config.get("max_inbound_wallet", 20))
        if node_type == NodeType.FARMER:
            return inbound_count < cast(int, self.config.get("max_inbound_farmer", 10))
        if node_type == NodeType.TIMELORD:
            return inbound_count < cast(int, self.config.get("max_inbound_timelord", 5))
        return False

    def is_trusted_peer(self, peer: WSChiaConnection, trusted_peers: dict[str, Any]) -> bool:
        return is_trusted_peer(
            host=peer.peer_info.host,
            node_id=peer.peer_node_id,
            trusted_peers=trusted_peers,
            trusted_cidrs=self.config.get("trusted_cidrs", []),
            testing=self.config.get("testing", False),
        )

    def set_capabilities(self, capabilities: list[tuple[uint16, str]]) -> None:
        self._local_capabilities_for_handshake = capabilities

    def ban_peer(self, host: str, ban_time: int) -> None:
        ban_until: float = time.time() + ban_time
        self.log.warning(f"Banning {host} for {ban_time} seconds")
        if host in self.banned_peers:
            self.banned_peers[host] = max(ban_until, self.banned_peers[host])
        else:
            self.banned_peers[host] = ban_until