The attack in Istanbul is a declaration of war on the Turkish state by Isis, which has created an extensive network of operatives aided by an apparent willingness within the Erdogan government to turn a blind eye in the past.

The Turkish military is now carrying out a major operation inside Syria against Isis and incurring significant losses. Sixteen soldiers were killed last week outside the town of al-Bab and two captured special forces troopers were burned alive by the Islamists. Isis now appears intent on striking back, taking jihad to the heart of Turkey. A stream of fighters has been intercepted in recent months attempting to come into the country from Syria along with discoveries of caches of weapons. The bloodshed that links the two sides of the border was highlighted by Turkish jets carrying out strikes in Syria today in direct retaliation, say Ankara, for the murders of 39 people at the nightclub.

Defectors from Isis have told The Independent how the leadership of the group, desperately defending Mosul in Iraq and the caliphate’s de facto capital of Raqqa, are instructing adherents to carry out bombings and shootings abroad.

Speaking recently in northern Syria, Abu Mutassim, an Isis defector, has described the level of increasing hatred towards Turkey among the jihadist leadership.

“It is a Muslim country whose rulers have turned against Islam, allying themselves with the Americans and the Russians,” he told The Independent. “They are seen as the worst of enemies – Daesh [Isis] has declared war on Turkey.”

While Western focus has been on the attacks in Europe, some of the worst atrocities have taken place in Turkey .

Isis has claimed credit for the Reina club massacre declaring that it was carried out by a “heroic soldier of the caliphate who attacked the most famous nightclub where the Christians were celebrating their pagan feast” on the orders of its leader Abu Bakr al-Baghdadi. Further retribution, it said, will come against Turkey, “a servant of the cross”.

Eight people have been arrested by the security agencies overnight, but the gunman, who, according to Turkish security sources, is believed to be from former Soviet Central Asia, Uzbekistan or Kyrgyzstan, and is said to have fled after the attack by hailing a taxi, remains on the run.

More raids are expected to take place, including at the Syrian border – the same border through which Isis, Jabhat al-Nusra, an al-Qaeda affiliate, which now calls itself Jabhat Fateh al-Sham, and other hardline Islamist groups were able to move men and arms to fight the forces of Bashar al-Assad and moderate rebel groups.

An Isis presence has been established since then in the same border areas with the group showing its lethal reach. Syrian activists who had fled the Assad regime but had also made a stand against the Islamist extremists have been attacked, a number of them murdered. Clerics in mosques in the town of Urfa routinely urged young men to serve Islam by joining Isis and al-Nusra.

Yassir Abdulhamid, an activist from Syria’s Idlib province was forced to flee the border area and moved to Istanbul following threats from Isis. He said: “I had to leave because of Daesh [Isis]. Places like Urfa became almost as dangerous as being inside Syria. We simply could not understand how Daesh could be there like that without the Turkish authorities knowing what was going on and without doing something about it. Of course, we have all heard about certain links, but it is better not to talk about these things, it is too risky.

In pictures: Istanbul nightclub attacked during New Year party Show all 9 1 /9 In pictures: Istanbul nightclub attacked during New Year party In pictures: Istanbul nightclub attacked during New Year party People talk to medics in an ambulance near the scene of an attack in Istanbul on 1 January 2017 AP In pictures: Istanbul nightclub attacked during New Year party People near the scene of an attack in Istanbul on 1 January 2017 AP In pictures: Istanbul nightclub attacked during New Year party Police secure area near an Istanbul nightclub, Turkey, January 1, 2017. Reuters In pictures: Istanbul nightclub attacked during New Year party Ambulances line up on a road leading to a nightclub where a gun attack took place during a New Year party in Istanbul, Turkey Reuters In pictures: Istanbul nightclub attacked during New Year party Turkish special force police officers and ambulances are seen at the site of an armed attack January 1, 2017 in Istanbul Getty In pictures: Istanbul nightclub attacked during New Year party People embrace near the scene of an attack in Istanbul, on New Year's Day AP In pictures: Istanbul nightclub attacked during New Year party Medics carry a wounded person after an attack at a popular nightclub in Istanbul on 1 January AP In pictures: Istanbul nightclub attacked during New Year party Turkish police secure the area at Ortakoy district under Bosphorus Bridge after the attack on Reina nightclub Getty Images In pictures: Istanbul nightclub attacked during New Year party People leave a nightclub in Istanbul after it was attacked on 1 January AP

“What happened at the nightclub is terrible. There have been two big Daesh attacks in Istanbul since I have been here. In places like Urfa or Killis [another border town] we were under threat because we were activists. Now, here in Istanbul, everyone is under threat from Daesh”.

The interior ministry in Ankara said today that 147 people had been detained in the past week over suspected ties to Isis. All possible precautions had been taken against an attack on New Year’s Eve with 17,000 policemen, some of them undercover, on duty, it stressed.

The fact that the slaughter was carried out at a venue which was likely to be a target despite the arrests and the other security measures show the ongoing potency of Isis. There is also the question of whether the killings, and others in the past, could have been prevented had the authorities acted against the jihadis earlier.

One reason for the failure to take action, it is claimed, is the complex tapestry of the conflict and the de-facto alliances which have sprung as a result. Turkish forces, while fighting Isis, have also been carrying out operations against the Kurds in Turkey and Syria. Isis has also been battling the Kurds in Syria and, in the past, has carried out attacks on Kurdish targets inside Turkey.