Skip to content
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

Adjust code for AsteroidOSSync/pull/216 #1

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

I-asked
Copy link

@I-asked I-asked commented May 2, 2024

This PR is merely a dependency of the following PR: AsteroidOS/AsteroidOSSync#216

I-asked added 6 commits April 30, 2024 09:12
- Use Connman for managing the TAP interface
- Rely on kernel packet fragmentation instead of a custom header
- Respect the negotiated MTU when choosing the TAP MTU
@@ -179,6 +179,6 @@ void BLE::onReceivedFromCompanion(const QByteArray &content) {
void BLE::onMtuChanged(int mtu) {
if (mCurrentMtu != mtu) {
mCurrentMtu = mtu;
emit mtuChanged(mtu);
emit mtuChanged(mtu - 3);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain the origin of this constant ? And extract it into a named macro maybe ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And squash thsi into the code that introduced it :)

@@ -10,8 +10,6 @@ ExecStart=/usr/bin/asteroid-tap2ble
Restart=always
User=ceres
Group=ceres
AmbientCapabilities=CAP_NET_ADMIN
NoNewPrivileges=true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's awkward to introduce those lines and delete them as part of the same PR. Could you squash those changes into one commit ?

@@ -1,4 +1,16 @@
# asteroid-tap2ble
asteroid-tap2ble
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention across our projects seems to be #

I don't care all that much but let's just stay consistent with what we already have https://github.com/AsteroidOS/asteroid-calculator/blob/master/README.md?plain=1#L1


This daemon creates a TAP interface and exposes a BLE service with a RX and a
TX characteristic. These map to read/write operations on that TAP interface.

D-Bus forwarding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a more helpful commit title would be "Document D-Bus forwarding"

#define TX_UUID "00001002-0000-0000-0000-00A57E401D05"
#define SERVICE_UUID "0000A071-0000-0000-0000-00A57E401D05"
#define RX_UUID "0000A001-0000-0000-0000-00A57E401D05"
#define TX_UUID "0000A002-0000-0000-0000-00A57E401D05"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change those ? If you are worried about backward compatibility since the protocol changes, don't worry, there are no users at the moment and it's undocumented, we're free to evolve it however we want.

}
close(sock);

qDebug() << "MTU reset to" << mtu;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a space after to necessary ? I never remember if this qDebug syntax does it automagically or not

const auto &value = it->second;

if (value.contains("Ethernet")) {
//QString name = value["Ethernet"].toMap()["Name"].toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop this ;)

qCritical() << "Failed to get IFFLAGS";
exit(1);
}
if (ifr.ifr_flags & IFF_UP) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's extract a few helpers to bring the interface up and to configure connman


void TAP::iffReset(int mtu) {
struct ifreq ifr = {};
auto sock = socket(PF_INET, SOCK_DGRAM, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this socket is just required to do ioctls, let's create it once as part of the constructor and keep the fd around.

// Poll the interface file descriptor
mNotifier = new QSocketNotifier(mFd, QSocketNotifier::Read, this);
QObject::connect(mNotifier, &QSocketNotifier::activated, this, &TAP::fdActivated);
ifr.ifr_mtu = mtu - MY_ETH_TAP_HARD_FRAME_SIZE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reuse the mtuChanged() function here to avoid code duplication and chances that implementations drift over time :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants