public-transport / hafas-client

JavaScript client for HAFAS public transport APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

issues porting some profiles to hafas-rs

Schmiddiii opened this issue · comments

As suggested in #238 I will make a separate issue for some of the issues I am having with porting profiles to Rust. Any of those issues could of course be my fault and work in hafas-client.

Version Error (Fixed)

I get a version error {"err":"VERSION","ver":"1.59"} (with varying versions) for the following profiles:

  • BLS
  • CMTA
  • Salzburg
  • TPG
  • VKG

Auth-Error (Fixed)

Implementing MicMac in the Rust-version solved some of the Auth-errors I was having, but some are still there. I noticed that all three had two different auth-keys defined (one in the index.js, one in json), both do not work. Do I have to combine them somehow?

  • OÖVV
  • VOR
  • VVV

No connections (=H890) (Had bike-friendly turned on)

The following profiles work fine for e.g. searching for stations, but for every query I tried, I cannot get journeys to work. This could also be because there are truly no connections present and I have no idea what connections even exist.

  • AVV
  • DART
  • DB-Busradar-NRW
  • Mobiliteit-Lu
  • VVT
  • SNCF (I think that one is not even included in hafas-client, but was there in hafas-rs so I still include it here)
  • ZVV
  • BLS
  • CMTA
  • TPG

Does not reply (Fixed)

This issue is for some endpoints that do not seem to reply to my queries at all.

  • HVV (for LocMatch queries) (Down)
  • Rejseplanen (for journeys queries) (only took a while longer than the rest)
  • SBB (Even with a https-url) (Down)

H890 (See no connection)

As you alredy mentioned in previously stated issue, this is an error with "journeys search unsuccessful", but as this is not that descriptive I will still include the profiles that do not work for that.

  • SNCF (I think that one is not even included in hafas-client, but was there in hafas-rs so I still include it here)
  • ZVV

As previously stated, these may also be issues exclusively with the Rust-version, but as you suggested a new issue and I currently have not set up hafas-client for testing, I am writing this here.

I get a version error {"err":"VERSION","ver":"1.59"} (with varying versions) for the following profiles: […]

These all work with hafas-client. Could it be that you're always sending a ver of 1.59, even if the respective HAFAS instance doesn't support this?

Note that you can use the ServerInfo to find the highest supported version (but there have been endpoints wrongly reporting their support):

const {hciVersion: v} = await client.serverInfo()

[…] I noticed that all three [OÖVV, VOR, VVV] had two different auth-keys defined (one in the index.js, one in json), both do not work.

Where did you see that? I don't think so.

Implementing MicMac in the Rust-version solved some of the Auth-errors I was having, but some are still there. Do I have to combine them somehow?

This is the authentication logic in hafas-client:

hafas-client/lib/request.js

Lines 104 to 126 in 0dc2308

if (profile.addChecksum || profile.addMicMac) {
if (!Buffer.isBuffer(profile.salt) && 'string' !== typeof profile.salt) {
throw new TypeError('profile.salt must be a Buffer or a string.')
}
// Buffer.from(buf, 'hex') just returns buf
const salt = Buffer.from(profile.salt, 'hex')
if (profile.addChecksum) {
const checksum = md5(Buffer.concat([
Buffer.from(req.body, 'utf8'),
salt,
]))
req.query.checksum = checksum.toString('hex')
}
if (profile.addMicMac) {
const mic = md5(Buffer.from(req.body, 'utf8'))
req.query.mic = mic.toString('hex')
const micAsHex = Buffer.from(mic.toString('hex'), 'utf8')
const mac = md5(Buffer.concat([micAsHex, salt]))
req.query.mac = mac.toString('hex')
}
}

The following profiles work fine for e.g. searching for stations, but for every query I tried, I cannot get journeys to work. This could also be because there are truly no connections present and I have no idea what connections even exist.

Connections as in journeys() results?

In hafas-client, each profile has an example.js file with example queries that should work with the respective endpoint. I just checked AVV and got some journeys back.

This issue is for some endpoints that do not seem to reply to my queries at all.

What do you mean? Not HTTP response?

H890

As you alredy mentioned in previously stated issue, this is an error with "journeys search unsuccessful", but as this is not that descriptive I will still include the profiles that do not work for that. […] ZVV

The journeys() example in p/zvv/example.js works.

Thanks for the hints. I have figured out some more things (and edited my issue to update the current status):

Version errors

It seems like my automatic code generation did not fill out the version-field sometimes leaving it blank, manually filling it out fixed this issue (but most went to the "no connection" issue).

H890

I noticed that for H890-issues in the logs, that it also was described by "no connection available", so I put all of them into the same section. I have tried some of the examples you provided without any success. It may be (even though I doubt it) that I also send more information to these endpoints than they actually need (e.g. loyalty cards). I will maybe try to set up hafas-client and try to replicate exactly the same request with both tomorrow.

Authentication

I noticed (and also replicated) that code you sent. My replication is here. I will also try to check that both hafas-rs and hafas-client have the same authentication after setting up hafas-client tomorrow. For the duplicated auth-fields, see for example OÖVV index.js and base.json.

In order to compare hafas-rs's requests to hafas-client's, you can run hafas-client with DEBUG=hafas-client; It will print both the raw request and response bodies (but not the headers, but that shouldn't make a difference with HAFAS mgate.exe APIs).

I figured out the "no connection"-issue. I had bike-friendy journeys turned on while testing. They are all fixed now. I have not yet looked at the auth-issues.

Regarding HVV not replying, this is also broken for me in hafas-client, I get:

FetchError: request to https://hvv-app.hafas.de/bin/mgate.exe?mic=6e66acf38fe68800754a5747d9d87fa6&mac=150c872707568c74c7555fabcfc9e89d failed, reason: getaddrinfo ENOTFOUND hvv-app.hafas.de
    at ClientRequest.<anonymous> (/path/to/hafas-client/node_modules/node-fetch/lib/index.js:1491:11)
    at ClientRequest.emit (node:events:513:28)
    at TLSSocket.socketErrorListener (node:_http_client:494:9)
    at TLSSocket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  type: 'system',
  errno: 'ENOTFOUND',
  code: 'ENOTFOUND'
}

Others work fine. Note that SBB also seems broken:

TypeError [ERR_INVALID_PROTOCOL]: Protocol "http:" not supported. Expected "https:"
    at new NodeError (node:internal/errors:393:5)
    at new ClientRequest (node:_http_client:186:11)
    at request (node:http:97:10)
    at /path/to/hafas-client/node_modules/node-fetch/lib/index.js:1468:15
    at new Promise (<anonymous>)
    at fetch (/path/to/hafas-client/node_modules/node-fetch/lib/index.js:1437:9)
    at /path/to/hafas-client/node_modules/fetch-ponyfill/fetch-node.js:13:12
    at Object.request (/path/to/hafas-client/lib/request.js:137:9)
    at Object.journeys (/path/to/hafas-client/index.js:214:18)
    at Object.<anonymous> (/path/to/hafas-client/p/sbb/example.js:18:8) {
  code: 'ERR_INVALID_PROTOCOL'
}

And it does not reply with https instead of http.

Regarding HVV not replying, this is also broken for me in hafas-client, I get: getaddrinfo ENOTFOUND hvv-app.hafas.de

True, HVV is an exception, they have shut off their endpoint AFAIK.

Others work fine. Note that SBB also seems broken:

SBB seems to be shut off, too.

I have now also fixed the authentication issue. It was because sometimes the salt was a hex-string, sometimes a normal string. I have also removed HVV and SBB. I would consider these issues to be fixed.