• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tari-project / tari / 18097567115

29 Sep 2025 12:50PM UTC coverage: 58.554% (-2.3%) from 60.88%
18097567115

push

github

web-flow
chore(ci): switch rust toolchain to stable (#7524)

Description
switch rust toolchain to stable

Motivation and Context
use stable rust toolchain


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Chores**
* Standardized Rust toolchain on stable across CI workflows for more
predictable builds.
* Streamlined setup by removing unnecessary components and aligning
toolchain configuration with environment variables.
  * Enabled an environment flag to improve rustup behavior during CI.
* Improved coverage workflow consistency with dynamic toolchain
selection.

* **Tests**
* Removed nightly-only requirements, simplifying test commands and
improving compatibility.
* Expanded CI triggers to include ci-* branches for better pre-merge
validation.
* Maintained existing job logic while improving reliability and
maintainability.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

66336 of 113291 relevant lines covered (58.55%)

551641.45 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

85.33
/comms/core/src/utils/multiaddr.rs
1
// Copyright 2019, The Tari Project
2
//
3
// Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4
// following conditions are met:
5
//
6
// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7
// disclaimer.
8
//
9
// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10
// following disclaimer in the documentation and/or other materials provided with the distribution.
11
//
12
// 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote
13
// products derived from this software without specific prior written permission.
14
//
15
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
16
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
18
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
20
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
21
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22
use std::{
23
    io,
24
    net::{IpAddr, SocketAddr, ToSocketAddrs},
25
};
26

27
use crate::multiaddr::{Multiaddr, Protocol};
28

29
/// Convert a multiaddr to a socket address required for `TcpStream`
30
/// This function resolves DNS4 addresses to an ip address.
31
pub fn multiaddr_to_socketaddr(addr: &Multiaddr) -> io::Result<SocketAddr> {
8✔
32
    let mut addr_iter = addr.iter();
8✔
33
    let network_proto = addr_iter
8✔
34
        .next()
8✔
35
        .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid address '{addr}'")))?;
8✔
36
    let transport_proto = addr_iter
8✔
37
        .next()
8✔
38
        .ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid address '{addr}'")))?;
8✔
39

40
    if addr_iter.next().is_some() {
6✔
41
        return Err(io::Error::new(
1✔
42
            io::ErrorKind::InvalidInput,
1✔
43
            format!("Invalid address '{addr}'"),
1✔
44
        ));
1✔
45
    }
5✔
46

47
    match (network_proto, transport_proto) {
5✔
48
        (Protocol::Dns4(domain), Protocol::Tcp(port)) => {
3✔
49
            let addr = format!("{domain}:{port}");
3✔
50
            addr.to_socket_addrs()
3✔
51
                .map_err(|_e| io::Error::new(io::ErrorKind::InvalidInput, format!("Invalid domain '{domain}'")))?
3✔
52
                .next()
2✔
53
                .map_or_else(
2✔
54
                    || {
×
55
                        Err(io::Error::new(
×
56
                            io::ErrorKind::InvalidInput,
×
57
                            format!("Invalid domain '{domain}'"),
×
58
                        ))
×
59
                    },
×
60
                    Ok,
61
                )
62
        },
63
        (Protocol::Ip4(host), Protocol::Tcp(port)) => Ok((host, port).into()),
1✔
64
        (Protocol::Ip6(host), Protocol::Tcp(port)) => Ok((host, port).into()),
1✔
65
        _ => Err(io::Error::new(
×
66
            io::ErrorKind::InvalidInput,
×
67
            format!("Invalid address '{addr}'"),
×
68
        )),
×
69
    }
70
}
8✔
71

72
/// Convert a socket address to a multiaddress. Assumes the protocol is Tcp
73
pub fn socketaddr_to_multiaddr(socket_addr: &SocketAddr) -> Multiaddr {
44✔
74
    let mut addr: Multiaddr = match socket_addr.ip() {
44✔
75
        IpAddr::V4(addr) => Protocol::Ip4(addr).into(),
44✔
76
        IpAddr::V6(addr) => Protocol::Ip6(addr).into(),
×
77
    };
78
    addr.push(Protocol::Tcp(socket_addr.port()));
44✔
79
    addr
44✔
80
}
44✔
81

82
#[cfg(test)]
83
mod test {
84
    use std::{net::Ipv4Addr, str::FromStr};
85

86
    use multiaddr::multiaddr;
87

88
    use super::*;
89

90
    #[test]
91
    fn multiaddr_to_socketaddr_ok() {
1✔
92
        fn expect_success(addr: &str, expected_ips: &[&str]) {
3✔
93
            let addr = Multiaddr::from_str(addr).unwrap();
3✔
94
            let sock_addr = super::multiaddr_to_socketaddr(&addr).unwrap();
3✔
95
            assert!(expected_ips.iter().any(|ip| *ip == sock_addr.ip().to_string()));
4✔
96
        }
3✔
97

98
        expect_success("/ip4/254.0.1.2/tcp/1234", &["254.0.1.2"]);
1✔
99
        expect_success("/ip6/::1/tcp/1234", &["::1"]);
1✔
100
        // Test DNS name resolution
101
        expect_success("/dns4/localhost/tcp/1234", &["127.0.0.1", "::1"]);
1✔
102
    }
1✔
103

104
    #[test]
105
    fn multiaddr_dns_to_socketaddr_ok() {
1✔
106
        let addr = Multiaddr::from_str("/dns4/localhost/tcp/1234").unwrap();
1✔
107
        let sock_addr = super::multiaddr_to_socketaddr(&addr).unwrap();
1✔
108
        assert!(sock_addr.ip().is_loopback());
1✔
109
    }
1✔
110

111
    #[test]
112
    fn multiaddr_to_socketaddr_err() {
1✔
113
        fn expect_fail(addr: &str) {
4✔
114
            let addr = Multiaddr::from_str(addr).unwrap();
4✔
115
            let err = super::multiaddr_to_socketaddr(&addr).unwrap_err();
4✔
116
            assert_eq!(err.kind(), io::ErrorKind::InvalidInput);
4✔
117
        }
4✔
118

119
        expect_fail("/ip4/254.0.1.2/tcp/1234/quic");
1✔
120
        expect_fail("/ip4/254.0.1.2");
1✔
121
        expect_fail("/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC");
1✔
122
        expect_fail("/dns4/doesntexist.theresnotldlikethis/tcp/1234")
1✔
123
    }
1✔
124

125
    #[test]
126
    fn multiaddr_from_components() {
1✔
127
        let ip: Ipv4Addr = "127.0.0.1".parse().unwrap();
1✔
128
        let addr = multiaddr!(Ip4(ip), Tcp(1456u16));
1✔
129
        let mut addr_iter = addr.iter();
1✔
130
        assert_eq!(addr_iter.next(), Some(Protocol::Ip4(ip)));
1✔
131
        assert_eq!(addr_iter.next(), Some(Protocol::Tcp(1456)));
1✔
132
        assert_eq!(addr_iter.next(), None);
1✔
133
    }
1✔
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc